主题:VB实时写并在外部打开报错的问题
各位VB高手,小弟请教:
我的代码中如下,在一个Form加载的代码中:
Set globalExcelApp = CreateObject("Excel.Application")
globalExcelApp.DisplayAlerts = False
Set globalExcelBook = globalExcelApp.Workbooks.Add
Set globalExcelSheet = globalExcelBook.Worksheets(1)
globalExcelApp.DisplayAlerts = False
globalExcelSheet.Range("A1:G1").Select
globalExcelSheet.Range("A1:G1").MergeCells = True
globalExcelSheet.Range("A1:G1") = "¹ÉƱ¼à¿Ø"
With globalExcelSheet
.Cells(2, 1) = "Str"
.Cells(2, 2) = "Price"
.Cells(2, 3) = "Mkt"
End With
'这里进行保存操作
globalExcelBook.SaveAs saveFileName, ReadOnlyRecommended:=True
globalExcelCellRowNum = 3
globalExcelCellColumnNum = 3
以后在其他事件处理函数中,都会有:
With globalExcelSheet
.Cells(2, 1) = "Str"
.Cells(2, 2) = "Price"
.Cells(2, 3) = "Mkt"
End With
'这里进行保存操作
globalExcelBook.SaveAs saveFileName, ReadOnlyRecommended:=True
这样的更新单元格的操作,现在如果我不在外部打开写入的excel文件,是没有问题的,但是一旦我双击打开正在写入的excel文件,就弹出错误:
Run-time error '-2147221080 (800401a8)':
Method 'Cells' of object '_Worksheet' failed
请教各位大牛,不知道如何能一边实时写excel文件,一边还能在外部打开进行查看,小弟不盛感激,多谢各位大牛赐教:)
我的代码中如下,在一个Form加载的代码中:
Set globalExcelApp = CreateObject("Excel.Application")
globalExcelApp.DisplayAlerts = False
Set globalExcelBook = globalExcelApp.Workbooks.Add
Set globalExcelSheet = globalExcelBook.Worksheets(1)
globalExcelApp.DisplayAlerts = False
globalExcelSheet.Range("A1:G1").Select
globalExcelSheet.Range("A1:G1").MergeCells = True
globalExcelSheet.Range("A1:G1") = "¹ÉƱ¼à¿Ø"
With globalExcelSheet
.Cells(2, 1) = "Str"
.Cells(2, 2) = "Price"
.Cells(2, 3) = "Mkt"
End With
'这里进行保存操作
globalExcelBook.SaveAs saveFileName, ReadOnlyRecommended:=True
globalExcelCellRowNum = 3
globalExcelCellColumnNum = 3
以后在其他事件处理函数中,都会有:
With globalExcelSheet
.Cells(2, 1) = "Str"
.Cells(2, 2) = "Price"
.Cells(2, 3) = "Mkt"
End With
'这里进行保存操作
globalExcelBook.SaveAs saveFileName, ReadOnlyRecommended:=True
这样的更新单元格的操作,现在如果我不在外部打开写入的excel文件,是没有问题的,但是一旦我双击打开正在写入的excel文件,就弹出错误:
Run-time error '-2147221080 (800401a8)':
Method 'Cells' of object '_Worksheet' failed
请教各位大牛,不知道如何能一边实时写excel文件,一边还能在外部打开进行查看,小弟不盛感激,多谢各位大牛赐教:)