- 帖子
- 25
- 主題
- 4
- 精華
- 0
- 積分
- 156
- 點名
- 0
- 作業系統
- vista
- 軟體版本
- office2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2010-5-13
- 最後登錄
- 2021-8-29
 
|
如何每次開啟選擇匯入文字檔之路徑
以下的程式是用錄製巨集的功能完成的
主要是要將文字檔匯入excel指定欄位
可是因為有時候文字檔路徑不一樣
致程式無法順利執行
不知道要怎樣改成可以跳出視窗選擇檔案路徑,才可以不用每次重錄巨集
希望有人能協助,謝謝- Sub Macro1()
- '
- ' Macro1 Macro
- ' 匯入檔案
- '
- '
- With ActiveSheet.QueryTables.Add(Connection:= _
- "TEXT;C:\Users\USER\Desktop\新會\99.txt", Destination:=Range("$A$2"))
- .Name = "99"
- .FieldNames = True
- .RowNumbers = False
- .FillAdjacentFormulas = False
- .PreserveFormatting = True
- .RefreshOnFileOpen = False
- .RefreshStyle = xlInsertDeleteCells
- .SavePassword = False
- .SaveData = True
- .AdjustColumnWidth = True
- .RefreshPeriod = 0
- .TextFilePromptOnRefresh = False
- .TextFilePlatform = 950
- .TextFileStartRow = 1
- .TextFileParseType = xlFixedWidth
- .TextFileTextQualifier = xlTextQualifierDoubleQuote
- .TextFileConsecutiveDelimiter = False
- .TextFileTabDelimiter = True
- .TextFileSemicolonDelimiter = False
- .TextFileCommaDelimiter = False
- .TextFileSpaceDelimiter = False
- .TextFileColumnDataTypes = Array(9, 1, 9, 9)
- .TextFileFixedColumnWidths = Array(38, 32, 28)
- .TextFileTrailingMinusNumbers = True
- .Refresh BackgroundQuery:=False
- End With
- ActiveWindow.SmallScroll Down:=-27
- End Sub
複製代碼 |
|