简体   繁体   English

对象“_Global”的运行时错误“1004”方法“工作表”失败

[英]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.

相关问题 运行时错误'1004':在某些工作表上,对象'Global'的方法'Range'失败,但是我的代码能够在大多数其他工作表上运行吗? - Run-time error '1004': Method 'Range' of object 'Global' failed, on some worksheets, but my code is able to run on most other worksheets? 运行时错误'1004':对象'_Global'的方法'Range'失败 - Run-time error '1004' : Method 'Range' of object'_Global' failed 运行时错误'1004':对象'_Global'的方法'Range'失败 - Run-time error '1004': Method 'Range' of object '_Global' failed 运行时错误'1004'对象'_Global'的方法'Range'失败 - Run-time error '1004' Method 'Range' of object'_Global' failed 运行时错误'1004':对象'_Global'的方法'Range'失败6 - Run-time error '1004' : Method 'Range' of object'_Global' failed 6 运行时错误'1004' - 对象'_Global'的方法'范围'失败 - Run-time error '1004' - Method 'Range' of object'_Global' failed 运行时错误“ 1004”:对象“ _Global”的方法“相交”失败 - Run-time error '1004': Method 'Intersect' of object' _Global' failed 运行时错误“1004”对象“_Global”的方法“行”失败 - Run-time error '1004' Method 'Rows' of object '_Global' Failed 运行时错误“1004”-object“_Global”的方法“范围”失败 - Run-time error '1004' - Method 'Range' of object '_Global' failed 运行时错误1004-对象'_Global'的方法'Range'失败 - Run-time error 1004 - Method 'Range' of object'_Global' failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM