Avatar of David Haycox
David Haycox
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Word 2003 macro in Word 2016 "Run-time error '5'"

We have two macros that were written for Word 2003, but now have to upgrade to Word 2016 on a new Remote Desktop server.  The macro shows up under the "Add-ins" tab but when we click it, we see the following error:

Microsoft Visual Basic
Run-time error '5':
Invalid procedure call or argument

Changing the Trust Center macro settings has no effect.

Is it possible to convert these macros to work in Word 2016?  If so, how?  If not, what are the next steps?
VBAMicrosoft WordDesktops

Avatar of undefined
Last Comment
Ramin

8/22/2022 - Mon
SOLUTION
Ramin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

what are the next steps?
try debug your codes.

this error could be machine specified and probably inherited from Word 2003?
David Haycox

ASKER
Here's the subroutine of the smaller of the two macros:

Sub GetPrintername(CurPrinter)
CurPrinter = Application.ActivePrinter
WordInStr = InStr(1, CurPrinter, " on ", vbTextCompare)
CurPrinter = Mid$(CurPrinter, 1, WordInStr - 1)
End Sub

Open in new window

It does indeed crash at the line containing the Mid().
If I delete the subroutine, the macro will run (but of course it won't work properly).
I don't have any experience of macros or VBA.  Could you give me a suggestion how to amend this code?  Many thanks.
ASKER CERTIFIED SOLUTION
Ramin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Haycox

ASKER
Fantastic, the macro now runs!  Also made the same change in the larger of the two.  Thanks very much!  We are testing it now.  Will post outcome in due course.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
David Haycox

ASKER
Yes, this works now,  There is a different problem regarding the behaviour of the macro, but that's a different story.  Will ask another question if necessary.  Thanks again!
Ramin

You're welcome,  I'm glad it works.