您好我试图将csv导入dumpWS。 当我取消打开文件时,这段代码工作正常,但是当我选择csv.file然后打开。这段代码给了我运行时错误' 13'类型missmatch。
它遇到问题的行是"如果strFile = False那么"
Private Sub CSV_Import()
Dim addDumpWS As Worksheet
Dim dumpWS As Worksheet, strFile As String
Set dumpWS = ThisWorkbook.Worksheets("DUMP")
' Clear all data in worksheet(DUMP) before import
dumpWS.Cells.Clear
strFile = Application.GetOpenFilename("CSV Files (*.csv),*.csv", , "Please select text file...")
' Message box when file is not selected
If strFile = False Then
ThisWorkbook.Worksheets("List").Select
Range("ImportStatus").Select
MsgBox "No file selected. Cannot continue import."
Exit Sub
Else
' Import select csv
With dumpWS.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=dumpWS.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With
' Copy imported data to WebDBDataBody
dumpWS.Activate
Rows(1).EntireRow.Delete
ActiveSheet.UsedRange.Select
Selection.Copy
Range("WebDBDataBody").PasteSpecial xlPasteValues
' Recorded Imported Date
Range("ImportedDate").Value = Date
End If
End Sub
答案 0 :(得分:0)
我改变了
如果strFile = False那么
要 如果strFile = Cstr(False)那么
它工作正常