[英]Run-time error '1004' Method 'Worksheets' of object'_Global' failed
I believe i have an unqualified reference issue with the code below, based on what I've read.根据我所阅读的内容,我相信我对下面的代码有一个不合格的参考问题。 I think what I need to do is reference the workbook specifically however I've tried a number of ways of doing this, all unsuccessfully.
我认为我需要做的是专门参考工作簿,但是我已经尝试了多种方法,但都没有成功。 Is anyone able to assist?
有人可以提供帮助吗?
Dim f As FileDialog, str As String
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.Show
str = f.SelectedItems(1)
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Visible = True
xl.Workbooks.Open (str)
Dim wsT As Worksheet, wsA As Worksheet, wsE As Worksheet, wsI As Worksheet, lr As Long, lrow As Long
Worksheets.Add(After:=Worksheets(1)).Name = "TABLE"
Set wsA = Worksheets("ACTIVE")
Set wsT = Worksheets("TABLE")
One example, of what I've tried was我尝试过的一个例子是
Set wb = xl.workbooks.open(str)
Thank you!谢谢!
You were almost there.你快到了。 Just define the variables first.
只需先定义变量。
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Visible = True
Dim xlWB as Excel.Workbook '** added this line
Set xlWB = xl.Workbooks.Open(str)
Rest of code looks good at first glance其余代码乍一看还不错
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.