0
我試圖從TXT文件導入數據到我的Excel工作表。將txt文件導入到excel中; QueryTables
它適用於低於VBA宏,但唯一的問題是重新打開Excel文件宏後試圖尋找txt目錄,當它無法找到它時,它是給出錯誤。
我不打算在那裏放置這樣的命令,但現在我不知道如何禁用它。你們有關於我應該改變什麼來禁用該功能的想法嗎?
Sub test_9()
Dim jess916 As Variant, FullPath As String
Set jess916 = Application.FileDialog(msoFileDialogFilePicker)
With jess916
.InitialView = msoFileDialogViewDetails
.InitialFileName = ThisWorkbook.Path
.Filters.Add "Open File ", "*.txt", 1
.ButtonName = "Import file"
.Title = " jess916c Search for .txt file to Import"
If .Show = -1 Then
FullPath = .SelectedItems(1)
Else:
Exit Sub
End If
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & FullPath, Destination:=Range("A2"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 9
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
你的意思是說你關閉了你的xlsx文件,你再次打開它,並且VBA宏自動運行? –