在VBA中,当我运行一段代码两次时,我得到错误1004

时间:2011-07-29 12:36:57

标签: access-vba

我有以下代码:

Dim objexcel1 As excel.Application
Dim wbexcel1 As excel.Workbook
Dim objSht1 As excel.Worksheet
Set objexcel1 = CreateObject("excel.Application")
'objexcel1.Visible = True 'Remove excel visibilty at start


Set wbexcel1 = objexcel1.Workbooks.Open("C:\CARS.xls")
Set objSht1 = wbexcel1.Worksheets("car")
objSht1.Activate


Columns("A:B").Select

Charts.Add
ActiveChart.chartType = xlXYScatter

我需要运行此代码两次。当我首先运行它运行正常但在第二次运行时它在Columns("A:B").Select

上给出了错误1004

1 个答案:

答案 0 :(得分:0)

是的,我得到了它我需要添加引用。