[算表] excel 匯入判斷問題

看板Office作者 (佩蒂吉他)時間9年前 (2017/01/26 16:14), 9年前編輯推噓0(006)
留言6則, 3人參與, 最新討論串1/1
軟體:excel 版本:2007 問題檔案 https://drive.google.com/open?id=0BwCgrQhGgaw7aHpkQkpYWDhoWnM 我有一段vba程式 是可以開啟檔案總館選擇csv檔案匯入 但我想要若是取消匯入的時候 可以中斷這個程式並跳出 已中斷 而且不會執行下面的clear動作 不知道要怎麼改 Sub 餘額檔匯入() Worksheets("餘額檔").Activate Dim ws As Worksheet, strFile As String, abc As String Set ws = ActiveWorkbook.Sheets("餘額檔") '設定要輸進去的工作表名稱 strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please selec csv file...") Sheets("餘額檔").Rows("3:100000").Select Selection.ClearContents Sheets("餘額檔").Columns("A:AB").Select Selection.ClearContents With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1")) .TextFileParseType = xlDelimited .TextFileCommaDelimiter = True .Refresh End With abc = Sheets("餘額檔").Range("A1").End(xlDown).Row Range("AC2:AQ2").Select Selection.AutoFill Destination:=Range("AC2:AQ" & abc) MsgBox "匯入完成" End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.252.11 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1485418496.A.E9B.html ※ 編輯: ptguitar (1.34.252.11), 01/26/2017 16:15:15

01/26 16:17, , 1F
多個判斷即可。試試 https://goo.gl/5SU5sB
01/26 16:17, 1F

01/27 02:09, , 2F
if strFile = "" then
01/27 02:09, 2F

01/27 02:10, , 3F
exit sub
01/27 02:10, 3F

01/27 02:10, , 4F
end if
01/27 02:10, 4F

01/27 02:10, , 5F
放在strFile = Application.GetOpenFilename( 的下一行
01/27 02:10, 5F

01/27 07:07, , 6F
感謝各位大大~
01/27 07:07, 6F
文章代碼(AID): #1OYR00wR (Office)
文章代碼(AID): #1OYR00wR (Office)