第二次保存时出现错误(实时错误 '1004' 对象 'Range' 的方法 '_Global' 失败)
首先在excel里录制一个表格的宏,将宏复制到vb里面,希望将两次得到的数据保存到同一个book1里面,当我第一次保存数据是正常,不关闭vb程序,第二次保存时出现错误(实时错误 '1004' 对象 'Range' 的方法 '_Global' 失败)我的程序如下:
这是录制的一部分宏:
Range("A1:A2").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
Range("A1:A2").Select
ActiveCell.FormulaR1C1 = "道次"
With ActiveCell.Characters(Start:=1, Length:=2).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
这是我的保存数据程序:
Private Sub Command22_Click()
n = Form1.List1.ListCount - 1
Dim wj As Excel.Application
Dim bo As Excel.Workbook
Dim sh As Excel.Worksheet
Set wj = CreateObject("Excel.Application")
Set bo = wj.Workbooks.Add
If x = 3 Then Set sh = bo.Worksheets.Add
Set sh = bo.Worksheets(1)
Call Macro1
bo.Close Savechanges:=ture '另存为
wj.Visible = True
Set sh = Nothing '关闭excel
Set bo = Nothing
Set wj = Nothing
End Sub --------------------编程问答-------------------- 要先退出excel,才可以nothing。
.
.
.
bo.Close Savechanges:=ture '另存为
wj.Visible = True
wj.quit '关闭excel
Set sh = Nothing
Set bo = Nothing
Set wj = Nothing
补充:VB , 数据库(包含打印,安装,报表)