编写一个Excel脚本的一些总结
2011-12-13 15:55
176 查看
VBA入门
/article/2731153.html
1. alt+F11 vba编程界面
2. Excel cell color and color index map:
#00FF00 4
#CCFFCC 35
FFFF00 6
FF0000 3
C0C0C0 15
http://dmcritchie.mvps.org/excel/colors.htm
3. when copy sheet to another workbook, the color of some cell is lost. You should first copy the custom color from source workbook to target workbook;
attention: when you change the color, but the color index is not change;
Such as: normally color index is map to #008000; when you changed the stardard color to #CCFFCC, but the color index
is not change.
http://www.excelbanter.com/showthread.php?t=102323
' copy color
targetWorkbook.Colors = targetWorkbook1.Colors
4. select and open excel file
Dim NewFN As String
Dim targetWorkbook1 As Workbook
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", title:="Please select first file")
If Len(NewFN) = 0 Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Set targetWorkbook1 = Workbooks.Open(Filename:=NewFN, ReadOnly:=False)
End If
5. the last sheet of excel can not be delete
Sub RemoveAllSheet(ByRef wb As Workbook)
Application.DisplayAlerts = False
Dim sh As Worksheet
For Each sh In wb.Worksheets
If sh.Name <> "Sheet1" Then sh.Delete
Next
Application.DisplayAlerts = True
End Sub
6. sheet copy
Sub CopyFirtstSheetToTarget(ByRef souce As Workbook, ByRef Target As Workbook)
Application.DisplayAlerts = False
souce.Sheets(1).Copy after:=Target.Sheets("Sheet1")
' rename
Dim sheetName As String
sheetName = ActiveSheet.Name
ActiveSheet.Name = souce.Name & "_" & sheetName
Application.DisplayAlerts = True
End Sub
7. get table range
Sub GetTableRange(ByRef lastTableIndex As Integer)
Last = ActiveSheet.Underline(Rows.count, "A").End(xlUp).Row
Dim myInterior As Interior
For i = TABLE_START_INDEX To Last
Set myInterior = ActiveSheet.Underline(i, "B").Interior
If (myInterior.ColorIndex = 5) Then
lastTableIndex = i
End If
Next i
End Sub
8. delete all content
Sub DeleteAllContent()
ActiveSheet.Underline.Clear
End Sub
/article/2731153.html
1. alt+F11 vba编程界面
2. Excel cell color and color index map:
#00FF00 4
#CCFFCC 35
FFFF00 6
FF0000 3
C0C0C0 15
http://dmcritchie.mvps.org/excel/colors.htm
3. when copy sheet to another workbook, the color of some cell is lost. You should first copy the custom color from source workbook to target workbook;
attention: when you change the color, but the color index is not change;
Such as: normally color index is map to #008000; when you changed the stardard color to #CCFFCC, but the color index
is not change.
http://www.excelbanter.com/showthread.php?t=102323
' copy color
targetWorkbook.Colors = targetWorkbook1.Colors
4. select and open excel file
Dim NewFN As String
Dim targetWorkbook1 As Workbook
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", title:="Please select first file")
If Len(NewFN) = 0 Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Set targetWorkbook1 = Workbooks.Open(Filename:=NewFN, ReadOnly:=False)
End If
5. the last sheet of excel can not be delete
Sub RemoveAllSheet(ByRef wb As Workbook)
Application.DisplayAlerts = False
Dim sh As Worksheet
For Each sh In wb.Worksheets
If sh.Name <> "Sheet1" Then sh.Delete
Next
Application.DisplayAlerts = True
End Sub
6. sheet copy
Sub CopyFirtstSheetToTarget(ByRef souce As Workbook, ByRef Target As Workbook)
Application.DisplayAlerts = False
souce.Sheets(1).Copy after:=Target.Sheets("Sheet1")
' rename
Dim sheetName As String
sheetName = ActiveSheet.Name
ActiveSheet.Name = souce.Name & "_" & sheetName
Application.DisplayAlerts = True
End Sub
7. get table range
Sub GetTableRange(ByRef lastTableIndex As Integer)
Last = ActiveSheet.Underline(Rows.count, "A").End(xlUp).Row
Dim myInterior As Interior
For i = TABLE_START_INDEX To Last
Set myInterior = ActiveSheet.Underline(i, "B").Interior
If (myInterior.ColorIndex = 5) Then
lastTableIndex = i
End If
Next i
End Sub
8. delete all content
Sub DeleteAllContent()
ActiveSheet.Underline.Clear
End Sub
相关文章推荐
- 程序员面试金典——解题总结: 9.18高难度题 18.9随机生成一些数字并传入某个方法。编写一个程序,每当收到新数字时,找出并记录中位数。
- Ethereal 也可以使用lua做一些自定义的功能了--编写lua脚本扩展ethereal的功能
- 程序员面试金典: 9.11 排序与查找 11.5有个排序后的字符串数组,其中散布这一些空字符串,编写一个方法,找出给定字符串的位置
- 同一个项目的不同的项目工作经验总结--设计文档编写经验总结
- 用groovy简化java反射编写一个基于行数据对象的自动生成excel文件对象的工具
- Linux学习之道:编写一个判断IP地址合法性的bash脚本
- 自己编写的一个查找Linux进程的Shell脚本
- 用excel做一个家庭流水账本 增加一些统计功能 和大家分享
- 个人总结的一个中高级Java开发工程师或架构师需要掌握的一些技能
- 如何编写一个shell脚本
- 编写一个程序,从标准输入读取一些字符,并把它们写到标准输出上。它同时应该计算checksum值,写在后面
- 编写一些代码,确定一个变量是有符号数还是无符号数(c专家编程摘录)
- shell脚本中一些特殊符号的总结
- 每天一个linux命令(62):sh命令 /Linux中执行shell脚本的4种方法总结
- 一个使用JAVA编写的类似按键精灵的程序,支持脚本文件编写(含源代码)
- 管理的网路设备较多,今天借助SNMP++ 编写了一个SNMP的COM控件,可以用VBS脚本批量查自己想要的数据了
- Ubuntu + Apache2 环境下用C编写 一个简单的cgi脚本
- 【shell脚本】如何用shell编写一个进度条
- fun函数声明的一些问题和编写函数的一个问题
- 一个使用JAVA编写的类似按键精灵的程序,支持脚本文件编写(含源代码)