+ Reply to Thread
Results 1 to 2 of 2

Splitter Macro

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Winchester
    MS-Off Ver
    Excel 2003
    Posts
    13

    Splitter Macro

    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

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Splitter Macro

    Please use code tags with your code.
    You are more likely to get a response if you post this thread in to word section of this site.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1