【发布时间】:2016-03-15 12:41:59
【问题描述】:
我正在尝试打开一个 CSV 文件(每天从另一个程序生成)并将数据复制到我当前工作簿中的某个工作表中。
我的复制/粘贴行出现运行时错误 438。
Sub GetCSV()
Dim thatWB As Workbook, thisWB As Workbook
Dim thisWS As Worksheet, thatWS As Worksheet
Dim zOpenFileName As String
Dim inputData As String
'get name of sheet to open
inputData = InputBox("Enter name of file")
'open CSV file
zOpenFileName = Application.GetOpenFilename
'error handling
If zOpenFileName = "" Then Exit Sub
Application.ScreenUpdating = False
Set thisWB = ThisWorkbook 'destination workbook
Set thisWS = Sheets("f_dump") 'destination worksheet
Set thatWB = Workbooks.Open(zOpenFileName) 'source CSV
Set thatWS = thatWB.Sheets(inputData) 'source worksheet
Application.CutCopyMode = False
thatWB.thatWS.Range("A1:G150").Copy Destination:=thisWB.thisWS.Range("A1")
thatWB.Close
End Sub
【问题讨论】: