View Single Post
 
Old 11-01-2020, 09:28 PM
macropod's Avatar
macropod macropod is offline Windows 10 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