Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below code arise "Out of range" error in Word document.(rare cases)

VB
outWord.ActiveDocument.PageSetup.LineNumbering.Active = False
Posted
Updated 12-Sep-15 8:07am
v2

1 solution

There could be many reasons such as:
- there is no active document or it has changed at the moment the code is executed
- the document has multiple sections etc.

However in order to solve the problem more information would be needed. So in my opinion you should wrap the operations inside a try...catch block and in case of an error gather all the information possible about the situation.

Another thing that could make the code more robust is that you would store the references inside a variable instead of referencing Active... For example in the beginning of the code set the ActiveDocument value in a Word.Document type of variable and use that variable to make modifications to the document. This often eliminates problems that occur when the active document changes.
 
Share this answer
 
Comments
aarif moh shaikh 12-Sep-15 8:28am    
Good one +5
Wendelius 12-Sep-15 9:07am    
Thank you!
Maciej Los 12-Sep-15 14:12pm    
Well explained, +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900