vb操作excel

时间:2016-09-27 04:42:22
【文件属性】:

文件名称:vb操作excel

文件大小:116KB

文件格式:DOC

更新时间:2016-09-27 04:42:22

vb excel

rivate Sub Command3_Click() Dim i As Long Dim j As Long Dim objExl As Excel.Application '声明对象变量 Me.MousePointer = 11 '改变鼠标样式 Set objExl = New Excel.Application '初始化对象变量 objExl.SheetsInNewWorkbook = 1 '将新建的工作薄数量设为1 objExl.Workbooks.Add '增加一个工作薄 objExl.Sheets(objExl.Sheets.Count).Name = "book1" '修改工作薄名称 objExl.Sheets.Add , objExl.Sheets("book1") '增加第二个工作薄在第一个之后 objExl.Sheets(objExl.Sheets.Count).Name = "book2" objExl.Sheets.Add , objExl.Sheets("book2") '增加第三个工作薄在第二个之后 objExl.Sheets(objExl.Sheets.Count).Name = "book3" objExl.Sheets("book1").Select '选中工作薄 For i = 1 To 50 '循环写入数据 For j = 1 To 5 If i = 1 Then objExl.Selection.NumberFormatLocal = "@" '设置格式为文本 objExl.Cells(i, j) = " E " & i & j Else objExl.Cells(i, j) = i & j End If Next Next objExl.Rows("1:1").Select '选中第一行 objExl.Selection.Font.Bold = True '设为粗体 objExl.Selection.Font.Size = 24 '设置字体大小 objExl.Cells.EntireColumn.AutoFit '自动调整列宽 objExl.ActiveWindow.SplitRow = 1 '拆分第一行 objExl.ActiveWindow.SplitColumn = 0 '拆分列 objExl.ActiveWindow.FreezePanes = True '固定拆分 objExl.ActiveSheet.PageSetup.PrintTitleRows = "$1:$1" '设置打印固定行 objExl.ActiveSheet.PageSetup.PrintTitleColumns = "" '打印标题 objExl.ActiveSheet.PageSetup.RightFooter = "打印时间: " & _ Format(Now, "yyyy年mm月dd日


网友评论