Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 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 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...