将数据从CSV复制到Excel错误

时间:2018-01-26 15:29:03

标签: excel vba excel-vba csv

我在激活步骤中收到错误438。我最初尝试使用value =值进行复制/粘贴。副本工作,但粘贴没有。然后我尝试了复制/粘贴,然后我在激活中添加了。

我可以这样做吗?或者我需要在从中复制数据之前将文件另存为XLS?最好只有CSV,但我可以根据需要创建然后删除XLS文件。

Sub Update_QSPI_Data()

Dim wbDT As Workbook
Dim wbQSPI As Workbook
Dim wsExport As Worksheet
Dim wsQSPI As Worksheet


Set wbDT = Workbooks("File the Macro is Run from/where I want the new data")
Set wsExport = wbDT.Worksheets("Tab I want the data on")

'First we want to clear the tab  of all hidden columns, formatting, and data.

'If there is a hidden cell then unhide all the columns. Prevents an error in the instance that
'no columns are hidden

Dim j As Long 'Index for unhiding columns
For j = 1 To 53
7 If wsExport.Cells(1, j).EntireColumn.Hidden = True Then
    wsExport.Cells(1, j).EntireColumn.Hidden = False
End If
Next j

'This is the equivalent of "Clear All" in the dropdown menu

wsExport.Range("A:BA").Clear

'Now we want to open up the new QSPI Data

'Workbooks.Open("Path")
Workbooks.Open ("C:\Users\Folders\Desktop\CSV_FILE.csv"), Local:=True 

Set wbQSPI = Workbooks("CSV_FILE")
Set wsQSPI = wbQSPI.Sheets(1) 
Dim lRow As Long 'Last Row of Data

lRow = Cells.Find(What:="*", _
                LookAt:=xlPart, _
                LookIn:=xlFormulas, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, _
                MatchCase:=False).Row


'copy the data
wbQSPI.wsQSPI.Activate
wbQSPI.wsQSPI.Range("A1:AL" & lRow).Select
Selection.Copy
wbDT.wsExport.Activate
wbDT.wsExport.Range("A1:AL" & lRow).PasteSpecial xlPasteAll

0 个答案:

没有答案