在TEXTBOX鍵入11-11,按下確認自動在K:/test/內搜索同名稱的檔案並開啓此檔 在K:/test/內放著許多.xlsm檔(如11-11.,11-12xlsm..等活頁簿及範本.xlsm) 若搜尋不到檔案時...則自動開啓範本.xlsm 不齒下問!以利學習!感恩?

2016-11-23 9:07 am
更新1:

原來我要用的是VB6的系統= ="難怪在VBA都沒問題!! cheng大...想要再請教若在VB6內如何運作了... Workbooks.Open DirPath & fs 這句在VB6內一直說此處需要物件... 而且好像不能對應KEYCODE 13...我把代碼改成如下...但還是不行... Private Sub textbox1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Tx = textbox1 & ".xlsm" DirPath = "K:\testroad\" fs = Dir(DirPath & "*.xlsm") Do Until fs = "" r = r + 1 If fs = Tx Then Workbooks.Open DirPath & fs textbox1 = "" Exit Sub End If fs = Dir Loop Workbooks.Open DirPath & "test123.xlsm" textbox1 = "" End If 再麻煩大大了@@"感恩

回答 (1)

2016-11-23 2:15 pm
✔ 最佳答案
拼拼湊湊一段試試
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Tx = TextBox1.Text & ".xlsm"

DirPath = "K:\test\"
fs = Dir(DirPath & "*.xlsm")
Do Until fs = ""
r = r + 1
If fs = Tx Then
Workbooks.Open DirPath & fs
TextBox1 = ""
Exit Sub
End If
fs = Dir
Loop

Workbooks.Open DirPath & "範本.xlsm"
TextBox1 = ""
End If
End Sub


收錄日期: 2021-05-03 13:49:47
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20161123010709AAgEr7o

檢視 Wayback Machine 備份