Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 11-01-2020, 09:28 PM
macropod's Avatar
macropod macropod is offline VBA deleting sections retains last section header and footer Windows 10 VBA deleting sections retains last section header and footer Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

With the code in the link, and assuming you're using early binding, you'd replace:
Code:
Dim Sctn1 As Section, Sctn2 As Section
with code like:
Code:
Dim wdApp as New Word.Application, wdDoc as Word.Document
Dim Sctn1 As Word.Section, Sctn2 As Word.Section
You'd also replace:
Code:
With Selection
  If .Sections.Count = 1 Then
    MsgBox "Selection does not span a Section break", vbExclamation
    Exit Sub
  End If
with the document reference. For example:
Code:
Set wdDoc = wdApp.Documents.Add (template reference)
With wdDoc
and you'd replace:
Code:
Set Sctn1 = .Sections.First: Set Sctn2 = .Sections.Last
with code like:
Code:
Set Sctn1 = .Sections(x): Set Sctn2 = .Sections(y)
where 'x' is the # of the first Section to be deleted and 'y' is the # of the first Section after the last Section to be deleted.

You'd also need to replace the loop:
Code:
  While .Sections.Count > 1
    .Sections.First.Range.Characters.Last.Delete
  Wend
with code that deletes the specified unwanted Sections. For example:
Code:
  .Range(.Sections(x).Range.Start, .Sections(y).Range.Start - 1).Delete
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA deleting sections retains last section header and footer Fixed last page header/footer without the use of section breaks HelpNeed Word VBA 2 06-27-2017 06:15 PM
different header/footer sections/ page numbers Angela H Word 4 07-01-2015 12:45 PM
VBA deleting sections retains last section header and footer Mail Merge is Deleting objects in my header and footer during the merge bgranzow Mail Merge 9 06-05-2015 05:03 AM
VBA deleting sections retains last section header and footer Advanced page numbering: section pages in header, document pages in footer Albus Word 12 12-12-2014 01:36 PM
Different Header Same Footer across two sections - Letterhead bostockm Word 1 07-21-2014 05:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:21 PM.


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