標題:
[發問]
請問各位大神如何簡化這個
[打印本頁]
作者:
john711101
時間:
2019-12-17 10:03
標題:
請問各位大神如何簡化這個
我需要B6格子內容去尋找對應的檔案開啟使用
目前程式碼如下,因太多種類平板使用會負荷不了,
謝謝
Dim myFileName As String
myFileName = Range("B6")
'300
If Range("B6") = "CJ" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\CJ\CJ.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CK" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\CK\CK.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CL" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\CL\CL.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CM" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\CM\CM.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CN" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\CN\CN.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CP" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU630\CP\CP.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CQ" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU640\CQ\CQ.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CR" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU640\CR\CR.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
If Range("B6") = "CS" Then
myFileName = ThisWorkbook.Path & "\paper\300\XZU640\CS\CS.xlsm"
Workbooks.Open Filename:=myFileName, UpdateLinks:=True
End If
複製代碼
作者:
jcchiang
時間:
2019-12-18 08:37
回復
1#
john711101
直接將欄位值套入myFileName內,就不用做判斷
myFileName = ThisWorkbook.Path & "\paper\300\XZU600\" & Range("B6") & "\" & Range("B6") & ".xlsm"
作者:
john711101
時間:
2019-12-18 16:05
回復
2#
jcchiang
謝謝J大指導
可是我的資料夾路徑不只一個
:L :L
作者:
ikboy
時間:
2019-12-18 16:39
2# 已經OK了, 以下衹是防止一下。
Sub zz()
Dim myFileName As String, s$
s = "JKLMNPQRS"
For i = 1 To Len(s)
If [B6] = "C" & Mid(s, i, 1) Then
s = "C" & Mid(s, i, 1)
Workbooks.Open ThisWorkbook.Path & "\paper\300\XZU600\" & s & "\" & s & ".xlsm", 1
End If
Next
End Sub
複製代碼
作者:
john711101
時間:
2019-12-19 10:52
回復
4#
ikboy
謝謝指導
抱歉因該是我說的不夠詳細
我的資料夾如圖
[attach]31564[/attach]
目前是已單一的去判斷抓取不過檔案太多會導致平板電腦負荷不了
有更好的 方式去開啟我需要的檔案再請指導
謝謝
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)