Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2019, 06:48 AM
Marcel Marcel is offline Word template with Macro keeps getting an error ''Run-time error 5941'' Windows 10 Word template with Macro keeps getting an error ''Run-time error 5941'' Office 2016
Novice
Word template with Macro keeps getting an error ''Run-time error 5941''
 
Join Date: Dec 2019
Posts: 2
Marcel is on a distinguished road
Default Word template with Macro keeps getting an error ''Run-time error 5941''

Hi All,

We use a standard template for our engineers so that they can report their activities after a job. Within the template there are several instructions texts and we remove them all by using a simple macro. The macro is hidden within a button.

I have just 1 on more then 100+ engineers with a run-time error. The macro worked fine before when the engineer was running win7, but when he switched to win10 it simply generates the error. We're using office 16.

The error is on this line:

Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle Char;4. Instruction heading Char")

What I simply do not understand is that the macro works perfectly on every computer, but just not on one laptop. I have tried to check all the word settings possible, but no luck. We have re-installed office several times, but no luck.

Hopefully somebody here can help me out.


Thanks in advance!
Reply With Quote
  #2  
Old 12-17-2019, 06:49 AM
Marcel Marcel is offline Word template with Macro keeps getting an error ''Run-time error 5941'' Windows 10 Word template with Macro keeps getting an error ''Run-time error 5941'' Office 2016
Novice
Word template with Macro keeps getting an error ''Run-time error 5941''
 
Join Date: Dec 2019
Posts: 2
Marcel is on a distinguished road
Default

Complete macro:

Private Sub CommandButton1_Click()
CommandButton1.Select
Selection.Delete

' Delinstr Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle Char;4. Instruction heading Char")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle;4. Instruction heading")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.VerticalPercentScrolled = 4
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle Char;4. Instruction heading Char")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Click here to enter a start date"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.VerticalPercentScrolled = 5
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle Char;4. Instruction heading Char")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Click here to enter an end date"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.LargeScroll Down:=1
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles( _
"Subtitle Char;4. Instruction heading Char")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Click here to enter a date."
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Reply With Quote
  #3  
Old 12-17-2019, 07:32 AM
gmayor's Avatar
gmayor gmayor is offline Word template with Macro keeps getting an error ''Run-time error 5941'' Windows 10 Word template with Macro keeps getting an error ''Run-time error 5941'' Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,311
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

Is the named style present on that PC?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 12-17-2019, 04:55 PM
Guessed's Avatar
Guessed Guessed is offline Word template with Macro keeps getting an error ''Run-time error 5941'' Windows 10 Word template with Macro keeps getting an error ''Run-time error 5941'' Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,981
Guessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to all
Default

The error would be caused when the style doesn't exist in that document. This will happen on any machine when the document is missing that exact stylename.

Those style names are VERY atypical and appear to have a semi-colon where I would have expected a comma (which would denote an alias). You only have to get one character wrong there and the macro will error because the style doesn't exist.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Error Message Run time Error 4605 baes10 Word VBA 1 08-30-2018 02:37 PM
Word template with Macro keeps getting an error ''Run-time error 5941'' 5941 error message in macro used in merge moneal62 Word VBA 6 01-18-2016 07:54 PM
Error 5941 when running my macro to auto populate fields throughout the word doc VBAnovice1 Word VBA 2 05-26-2015 01:35 AM
Run-time error 5941 when deleting a row from a table jpb103 Word VBA 1 05-26-2014 07:08 AM
Word Visual Basic error - run time error 504 crazymorton Word 11 01-13-2012 04:32 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 10:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft