我試着下面的代碼,以避免寫太多的行(因爲列表很長 - 超過134),但在嘗試打開文件的行中出現錯誤。數組與參考文件的路徑打開文件
下面是代碼的一個想法:
Sub update_chemicals()
'update chemical database with macroeconomic indicators
'Dim local_main As String
Dim mylocal As Variant
Dim local_final As String
Dim myname As Variant
Dim name_final As String
'disrectories references
Dim local_1 As String
Dim local_2 As String
Dim local_3 As String
Dim local_4 As String
Dim local_5 As String
'Files
Dim name_1 As String
Dim name_2 As String
Dim name_3 As String
Dim name_4 As String
Dim name_5 As String
'Coal
local_1 = "G:\path\01. CARVAO\Carvao.V1.xlsm"
name_1 = "Carvao.V1.xlsm"
'Perlita
local_2 = "G:\path\Perlita.xlsm"
name_2 = "Perlita.xlsm"
'Diatomaceus Earth
local_3 = "G:\path\Terra_Diatomacea.xlsm"
name_3 = "Terra_Diatomacea.xlsm"
'Chloridric Acid
local_4 = "G:\path\Chloridric_Acid_v2.xlsm"
name_4 = "Chloridric_Acid_v2.xlsm"
'Hexane and Gasoline
local_5 = "G:\path\Price History - Hexane and Gasoline - PLATTS - Jan'17.xlsm"
name_5 = "Price History - Hexane and Gasoline - PLATTS - Jan'17.xlsm"
mylocal = Array("local_1", "local_2", "local_3", "local_4", "local_5")
myname = Array("name_1", "name_2", "name_3", "name_4", "name_5")
'/////////////////////////////////////////////// COAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
For x = 0 To 4
local_final = mylocal(x)
name_final = myname(x)
Workbooks.Open filename:=local_final
當我嘗試打開該文件
你能幫助我出現錯誤?
除去周圍的報價你Array(「local_1」,「local_2」...),以便它是Array(local_1,local_2 .......)與myname數組相同。 –