i**M 发帖数: 108 | 1 ThisWorkbook.Activate
Sheets("aa").Activate
mycount = Application.CountA(Range("A5:A100"))
For i = 2 To mycount
transdate = Cells(i, 1).Text
NameFile1 = "C:\Documents and Settings\Desktop" & bb& ".xlsx"
Set wb =Workbooks.Open(Filename:=NameFile1)
Next i
I want to read files' name from a spreadsheet and open those files. The
above is the vba code I wrote, but i got "application defined or object
defined error". I am a beginner of vba, anyone please help me. Thanks a
bunch! |
S*********g 发帖数: 5298 | 2 what is bb?
【在 i**M 的大作中提到】 : ThisWorkbook.Activate : Sheets("aa").Activate : mycount = Application.CountA(Range("A5:A100")) : : For i = 2 To mycount : : transdate = Cells(i, 1).Text : NameFile1 = "C:\Documents and Settings\Desktop" & bb& ".xlsx" : Set wb =Workbooks.Open(Filename:=NameFile1) : Next i
|
i**M 发帖数: 108 | 3
bb is a string variable defined already
【在 S*********g 的大作中提到】 : what is bb?
|
S*********g 发帖数: 5298 | 4 你用F8一行一行的运行,看看是在那一行出的错
【在 i**M 的大作中提到】 : : bb is a string variable defined already
|
i**M 发帖数: 108 | 5
Workbooks.Open Filename:=NameFile1
is wrong, but have no idea how to fix it
【在 S*********g 的大作中提到】 : 你用F8一行一行的运行,看看是在那一行出的错
|
S*********g 发帖数: 5298 | 6 你的问题不在这一行。
bb&应该是bb &,否则应该编译不通过
另外你这个bb在这段code里没有定义,bb和你的循环变量没有关系
我估计你的问题是在bb这个变量
【在 i**M 的大作中提到】 : : Workbooks.Open Filename:=NameFile1 : is wrong, but have no idea how to fix it
|
i**M 发帖数: 108 | 7 Thanks for reply. I just replaced my variable by bb and i wrote & bb & in my
code. when I delete that open file code, it comliles alright.
【在 S*********g 的大作中提到】 : 你的问题不在这一行。 : bb&应该是bb &,否则应该编译不通过 : 另外你这个bb在这段code里没有定义,bb和你的循环变量没有关系 : 我估计你的问题是在bb这个变量
|
b***a 发帖数: 11 | 8 "C:\Documents and Settings\Desktop"
后面要加"\"
【在 i**M 的大作中提到】 : Thanks for reply. I just replaced my variable by bb and i wrote & bb & in my : code. when I delete that open file code, it comliles alright.
|
S*******r 发帖数: 11017 | 9 bingo
【在 b***a 的大作中提到】 : "C:\Documents and Settings\Desktop" : 后面要加"\"
|