我有三个不同的变量x,y& Z存储不同的名称。我必须打开一个基于格式x_y_z.xls
的文件dim x,y,z as string
x= abc
y= def
z= ece
Const strfolder As String = "C:\Users\source\"
Const samepattern As String = "x_y_Z.xls"
samefiletype = Dir(strfolder & samepattern, vbNormal)
workbooks.open(samefiletye)
由于某种原因,我必须将文件名保存在临时变量x,y和amp; z并传递它以基于变量名称打开文件。我无法根据变量名打开文件。
答案 0 :(得分:1)
const不应该总是不变吗?你试图将变量分配给常数。也许将它声明为变量。
dim x,y,z, strfolder, samepattern as string
x= abc
y= def
z= ece
strfolder = "C:\Users\source\"
samepattern = x & "_" & y &"_" & Z & ".xls"
samefiletype = Dir(strfolder & samepattern, vbNormal)
workbooks.open(samefiletye)
答案 1 :(得分:-1)
更改以下代码。
dim x,y,z as string
x= "abc"
y= "def"
z= "ece"
Const strfolder As String = "C:\Users\source\"
Const samepattern As String = x & "_" & y &"_" & Z & ".xls"
samefiletype = Dir(strfolder & samepattern, vbNormal)
workbooks.open(samefiletye)