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?
LVL 2
David HaycoxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RaminTechnical AdvisorCommented:
"Run-time error 5" when you use Mid(), Left(), or Right() function.  if one of these function are used in that macro check this link:
https://support.microsoft.com/en-us/help/290969/-run-time-error-5-when-you-use-mid---left---or-right-function
0
Ryan ChongCommented:
what are the next steps?
try debug your codes.

this error could be machine specified and probably inherited from Word 2003?
0
David HaycoxAuthor Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RaminTechnical AdvisorCommented:
Try this:

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David HaycoxAuthor Commented:
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.
1
David HaycoxAuthor Commented:
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!
1
RaminTechnical AdvisorCommented:
You're welcome,  I'm glad it works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.