Microsoft Office Forums Run Time Error 5843 When Applying Border

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2019, 05:30 PM
poetofpiano poetofpiano is offline Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Novice
Run Time Error 5843 When Applying Border
 
Join Date: Sep 2015
Posts: 20
poetofpiano is on a distinguished road
Default Run Time Error 5843 When Applying Border

I have a macro that applies a border as follows:



Code:
With Selection
    With .Borders(wdBorderLeft)
        .LineStyle = wdLineStyleSingle 
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With .Borders(wdBorderRight)
        .LineStyle = wdLineStyleSingle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With .Borders(wdBorderTop)
        .LineStyle = wdLineStyleSingle 
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With .Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle 
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
End With
It works fine when I have selected about a page worth of text. However, when I select around two pages worth and run the code, I get "Run Time Error 5843: one of the values passed to this method or property is out of range." Can anyone offer any help? Thank you so much!
Reply With Quote
  #2  
Old 09-13-2019, 02:05 AM
gmayor's Avatar
gmayor gmayor is online now Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,946
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

Your macro works with multiple pages of text. What else is on the page?
__________________
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
  #3  
Old 09-13-2019, 12:10 PM
poetofpiano poetofpiano is offline Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Novice
Run Time Error 5843 When Applying Border
 
Join Date: Sep 2015
Posts: 20
poetofpiano is on a distinguished road
Default

It seems to be a problem when there are a large number of short paragraphs in a row. For example, I have been able to reproduce the issue by pasting the following in a new Word doc (enough to cover two pages):

Code:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti. 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit diam at eros luctus, et porta risus pulvinar. Suspendisse potenti.
If you then select all of that text and run the macro, I get the error, and when I opt to debug, it highlights this macro line in yellow:

Code:
.LineWidth = Options.DefaultBorderLineWidth
Note that when you select only a page of the above text and run the macro, it works. Even selecting a page and a half works. But two pages produces the error.

Does this help pinpoint the issue?
Reply With Quote
  #4  
Old 09-13-2019, 07:56 PM
gmayor's Avatar
gmayor gmayor is online now Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,946
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

Unfortunately not, but I can now repeat the issue.
__________________
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
  #5  
Old 09-14-2019, 05:58 PM
eduzs eduzs is offline Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2010 32bit
Competent Performer
 
Join Date: May 2017
Posts: 174
eduzs is on a distinguished road
Default

The specified line width is not valid for border line style wdLineStyleSingle, so this generates an error.
Without setting the line width, you don't get the expected result? You might try other border styles.
__________________
Backup your original file before doing any modification, test in a throwaway copy of your file.
Reply With Quote
  #6  
Old 09-14-2019, 07:53 PM
gmayor's Avatar
gmayor gmayor is online now Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,946
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

It doesn't matter what you set the line width to - the error still occurs.
__________________
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
  #7  
Old 09-15-2019, 02:37 AM
eduzs eduzs is offline Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2010 32bit
Competent Performer
 
Join Date: May 2017
Posts: 174
eduzs is on a distinguished road
Default

Yes, thanks. The error occurs only when there is a blank paragraph between paragraphs, precisely between the end of 2nd and start of the 3rd page.
__________________
Backup your original file before doing any modification, test in a throwaway copy of your file.
Reply With Quote
  #8  
Old 09-16-2019, 12:24 PM
poetofpiano poetofpiano is offline Run Time Error 5843 When Applying Border Windows 10 Run Time Error 5843 When Applying Border Office 2016
Novice
Run Time Error 5843 When Applying Border
 
Join Date: Sep 2015
Posts: 20
poetofpiano is on a distinguished road
Default

Thank you both for your help. It’s unfortunate this bug exists, but at least the following works to approximate what I was going for:

Code:
With Selection.Borders
.Enable = True
.InsideLineStyle = False
End With
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
Applying individual border sides to images when pasted into a table Duvdev Word VBA 1 03-27-2014 03:12 AM
Get Run-time Error 11 Jamtart PowerPoint 2 08-31-2012 05:04 AM
Does Word do this when applying Styles to a paragraph a second time? Bobosmite Word 2 04-17-2012 02:13 PM
Word Visual Basic error - run time error 504 crazymorton Word 11 01-13-2012 04:32 AM


All times are GMT -7. The time now is 03:04 AM.


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