[VBA ] 如何傳送指定資料到不同的sheet裡
我是在excel sheet1寫的巨集
在不開啟檔案的情況下
想將資料傳送到sheet2
以下巨集是我目前的寫法
Dim myCnc1 As String
Dim myCnc2 As String
Dim myCnc3 As String
Dim myCmd As String
Dim myQryTbl As QueryTable
Dim myFileName As String
Dim a As String
Dim b As String
a = Range("ak2").Value
b = Range("ak3").Value
myFileName = a & "\" & b & ".xls"
myCnc1 = "ODBC;"
myCnc2 = "DBQ=" & ThisWorkbook.Path & "\" & myFileName & ";"
myCnc3 = "Driver={Microsoft Excel Driver (*.xls)};"
myCmd = "SELECT * FROM [1$]"
With ActiveSheet.QueryTables.Add( _
Connection:=myCnc1 & myCnc2 & myCnc3, _
Destination:=Worksheets("sheet2").Range("BB1"))
.CommandText = myCmd
.Refresh
End With
黃色是偵錯的部分
並出現
執行階段錯誤'-2147024809 (80070057)':
目標範圍不在查詢表單所在的工作表上
小弟我是新手
還望各位高手能救救我
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.69.78