Dim Excelapp As New Excel.Application
Dim wb As Excel.Workbook
Dim sh As Excel.Worksheet
On error goto ErrOutDataToExcel
后面是给赋值....最后
wb.SaveAs (Filename)
Excelapp.Visible = True
Set Excelapp = Nothing
Set wb = Nothing
Set sh = NothingErrOutDataToExcel:
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
Set Excelapp = Nothing
Set wb = Nothing
Set sh = Nothing可问题是,当Filename有重复时,他会问你是不是需要覆盖,如果选择是的话,则一切正常.如果选择"否"或者"取消"的话,则wb.SaveAs (Filename)会出错.然后Set Excelapp = Nothing Set wb = Nothing Set sh = Nothing可是这时如果打开Excel,再关掉,他会问你BookN需不需要保存(N是跟你程序运行的次数有关).说明我前面的程序影响到Excel的正常工作了.怎么解决这个问题,就是当我wb.SaveAs (Filename)出错时能不影响到Excel? Excelapp.Quit也不行,也有同样问题存在
Dim wb As Excel.Workbook
Dim sh As Excel.Worksheet
On error goto ErrOutDataToExcel
后面是给赋值....最后
wb.SaveAs (Filename)
Excelapp.Visible = True
Set Excelapp = Nothing
Set wb = Nothing
Set sh = NothingErrOutDataToExcel:
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
Set Excelapp = Nothing
Set wb = Nothing
Set sh = Nothing可问题是,当Filename有重复时,他会问你是不是需要覆盖,如果选择是的话,则一切正常.如果选择"否"或者"取消"的话,则wb.SaveAs (Filename)会出错.然后Set Excelapp = Nothing Set wb = Nothing Set sh = Nothing可是这时如果打开Excel,再关掉,他会问你BookN需不需要保存(N是跟你程序运行的次数有关).说明我前面的程序影响到Excel的正常工作了.怎么解决这个问题,就是当我wb.SaveAs (Filename)出错时能不影响到Excel? Excelapp.Quit也不行,也有同样问题存在
debug.print "File Exists"
else
debug.print "Not Found"
end if