Excel 对象变量或未设置块变量-运行时错误';91';
我有一些简单的复制和粘贴VBA代码在Excel中,这是以前的工作。可能有某种更新,因为现在我一直在标题中得到错误。代码如下: y.表格(“数据”).范围(“A1”).PasteSpecialExcel 对象变量或未设置块变量-运行时错误';91';,excel,vba,Excel,Vba,我有一些简单的复制和粘贴VBA代码在Excel中,这是以前的工作。可能有某种更新,因为现在我一直在标题中得到错误。代码如下: y.表格(“数据”).范围(“A1”).PasteSpecial Private Sub CommandButton1_Click() Dim x As Workbook Dim y As Workbook Set x = Workbooks.Open("https://nameofComp.sharepoint.com/sites/TechnicalBusines
Private Sub CommandButton1_Click()
Dim x As Workbook
Dim y As Workbook
Set x =
Workbooks.Open("https://nameofComp.sharepoint.com/sites/TechnicalBusiness/SharePoint%20-
%20Technical%20Business/Business%20Architects/Timesheet/Timesheet.xlsm")
Set y =
Workbooks.Open("https://nameofComp.sharepoint.com/sites/TechnicalBusiness/SharePoint%20-
%20Technical%20Business/Technical%20Coordaintor/Timesheet%20Anaysis/TimehsheetAnalysis.xlsm")
x.Sheets("Form1").Range("A2:U1000").Copy
Application.DisplayAlerts = False
y.Sheets("Data").Range("A1").PasteSpecial
x.Close
End Sub
我哪里出错了?试试下面的方法
Private Sub CommandButton1_Click()
Dim x As Workbook
Dim y As Workbook
Set x =
Workbooks.Open("https://nameofComp.sharepoint.com/sites/TechnicalBusiness/SharePoint%20-
%20Technical%20Business/Business%20Architects/Timesheet/Timesheet.xlsm")
Set y =
Workbooks.Open("https://nameofComp.sharepoint.com/sites/TechnicalBusiness/SharePoint%20-
%20Technical%20Business/Technical%20Coordaintor/Timesheet%20Anaysis/TimehsheetAnalysis.xlsm")
Application.DisplayAlerts = False
x.worksheets("Form1").Range("A2:U1000").Copy
y.worksheets("Data").Range("A1").PasteSpecial Paste:=xlPasteAll
x.Close
End Sub
工作簿。如果工作簿已打开,则打开
可能会导致问题
由于代码在工作簿y
中,请使用thiswoolk
:
Set y = ThisWorkbook
您是否可以在不使用vba的情况下对文件进行读写访问?@BigBen我已将其添加到问题中-对不起,是否有任何工作簿已打开?更新后,我假设您在目标wbI中没有
工作表(“数据”)
,我可能需要找到类似的问题,但是我相信如果工作簿已经打开,那么工作簿。打开
可能会导致问题。粘贴
是一个可选参数,因此如果这可以解决问题,我会感到惊讶。不,很抱歉,这没有解决问题-同一行仍然存在问题