我做错了什么?我简化了此代码,将一系列数据从一个工作簿复制并粘贴到另一个工作簿。但我收到文件路径错误消息??
我在线搜索过,但仍在努力寻找解决方案。任何帮助都很棒。干杯!
Sub GetDataFromGA3()
Dim wbTarget As Workbook 'where the data will be pasted
Dim wbSource As Workbook 'where the data will be copied
Dim StrName As String 'name of the source sheet
Application.ScreenUpdating = False 'these two statements help performance by disabling the self titled in each
Application.DisplayAlerts = False
Set wbSource = ActiveWorkbook 'set to the current workbook
StrName = ActiveSheet.Name 'get active sheetname of workbook
Set wbSource = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\Test File\metrics list" & "\") 'open source workbook
Set wbTarget = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\MASTER\Weekly logbook 2016" & "\") 'open target workbook
wbSource.Range("A1:E60").Copy 'copy range from sourcebook
wbTarget.Sheets("Sheet6").Range("D1:H60").PasteSpecial
wbTarget.Save ' save workbook
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
答案 0 :(得分:2)
这里有几个问题:
<强> 1。文件路径不正确
Set wbSource = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\Test FIle\metrics list" & "\") 'open source workbook
Set wbTarget = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\MASTER\Weekly logbook 2016" & "\") 'open target workbook
应该像:
Set wbSource = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\Test FIle\metrics list.xlsx") 'enter appropriate file extension
Set wbTarget = Workbooks.Open("C:\Users\jjordan\Desktop\Test Dir\MASTER\Weekly logbook 2016.xlsx") 'enter appropriate file extension
<强> 2。工作表名称缺失
wbSource.Range("A1:E60").Copy 'copy range from sourcebook
应该是:
wbSource.Sheets("Sheet_Name").Range("A1:E60").Copy 'enter appropriate sheet name
答案 1 :(得分:0)
尝试使用此斜杠:/
此外,您的文件路径未指向文件。如果您的文件名为“指标列表”,那么您的路径必须是
Set wbSource = Workbooks.Open("C:/Users/jjordan/Desktop/Test Dir/Test File/metrics list.xlsx"
(或其他文件结尾)