VBA to see if a Section exists in Word Document, and if it does, delete it

Joined
Nov 26, 2020
Messages
3
Reaction score
0
Hi, I'm trying to use VBA to see if a section exists in my Word document, and if it does, delete it... I will then add a section again and insert some auto text (This part is working fine).
The trouble I'm having, is with the "If a section exists" part.

I have used the following code which works, but ONLY if the section exists (it errors if the sections don't exist):
Dim SECS As Word.Section
Set SECS = ActiveDocument.Sections(7)
SECS.Range.Select
SECS.Range.Delete

Dim SECS1 As Word.Section
Set SECS1 = ActiveDocument.Sections(6)
SECS1.Range.Select
SECS1.Range.Delete

Any help would be much appreciated
 
Joined
Nov 26, 2020
Messages
3
Reaction score
0
Any help on the above would still be REALLY appreciated. I just cannot work it out! Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top