I have a splitter macro for Word 2007. What I want to happen is for it to close the current active window when it runs but then make the new window the active one so that it continues to split the original document. The VBA code is below:
Sub SplitMergeLetterAuto()
Dim sName As String
Dim docName As String
Dim Letters As String
Dim Counter As Long
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
oDoc.Save
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
docName = "C:\07-08 Scorecard Data\" & sName & ".doc"
oDoc.Sections.First.Range.Cut
Set oNewDoc = Documents.Add
Selection.WholeStory
With Selection
.PasteAndFormat wdFormatOriginalFormatting
.HomeKey Unit:=wdStory
End With
oNewDoc.SaveAs FileName:=docName, _
FileFormat:=wdFormatDocument, _
AddToRecentFiles:=False
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub
Thanks in advance
Bookmarks