Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

vba - Windows().Activate works on every computer except one

I have encountered a strange problem, I made macro about a year ago and it is being used every month without problems. Yesterday my boss told me, he cannot use it anymore, that it gives him some errors. I now tried the macro on 8 computers and the macro ran perfectly. Why is it that macro runs on everyone else's computer, except for my boss.

The line it breaks on

Windows("MyxlsbFile").Activate

And the error given is

Run-time error '9': Subscript out of range.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Whether or not you can leave off the file extension when calling (eg)

Windows("MyxlsbFile") 

or

Workbooks("MyxlsbFile")

depends on whether the Windows Explorer setting "hide extensions for known file types" has been checked or not: if file extensions are shown in Windows Explorer then you must include the extension when calling WorkBooks().

I'm guessing this is the issue on the one PC where you have the problem.

Including the file extension always works (as long as there's no other error of course)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...