Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-28-2013, 01:23 AM
donny12 donny12 is offline Splitter Macro for Word 2007 Windows XP Splitter Macro for Word 2007 Office 2007
Novice
Splitter Macro for Word 2007
 
Join Date: Jun 2013
Posts: 1
donny12 is on a distinguished road
Default Splitter Macro for Word 2007


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:

Code:
 
1.                                   Sub SplitMergeLetterAuto()
2.                                   Dim sName As String
3.                                   Dim docName As String
4.                                   Dim Letters As String
5.                                   Dim Counter As Long
6.                                   Dim oDoc As Document
7.                                   Dim oNewDoc As Document
8.                                   Set oDoc = ActiveDocument
9.                                   oDoc.Save
10.                               
11.                               Selection.EndKey Unit:=wdStory
12.                               Letters = Selection.Information(wdActiveEndSectionNumber)
13.                               Selection.HomeKey Unit:=wdStory
14.                               Counter = 1
15.                               While Counter < Letters
16.                               Application.ScreenUpdating = False
17.                               With Selection
18.                               
19.                               .HomeKey Unit:=wdStory
20.                               .EndKey Unit:=wdLine, Extend:=wdExtend
21.                               .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
22.                               
23.                               End With
24.                               sName = Selection
25.                               docName = "C:\07-08 Scorecard Data\" & sName & ".doc"
26.                               
27.                               oDoc.Sections.First.Range.Cut
28.                               Set oNewDoc = Documents.Add
29.                               Selection.WholeStory
30.                               With Selection
31.                               .PasteAndFormat wdFormatOriginalFormatting
32.                               .HomeKey Unit:=wdStory
33.                               End With
34.                               oNewDoc.SaveAs FileName:=docName, _
35.                               FileFormat:=wdFormatDocument, _
36.                               AddToRecentFiles:=False
37.                               ActiveWindow.Close
38.                               Counter = Counter + 1
39.                               Application.ScreenUpdating = True
40.                               Wend
41.                                End Sub
Thanks in advance
Reply With Quote
  #2  
Old 09-29-2013, 09:00 PM
macropod's Avatar
macropod macropod is offline Splitter Macro for Word 2007 Windows 7 32bit Splitter Macro for Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Coded properly, there is no need to the macro to close any windows - all you need to do is to tell the code which document to run against. There is also no need to use all that selection-based code. Range-based code is much more efficient and much less prone to screen flickering.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitter Macro for Word 2007 Macro fails to add image border in Word 2007 samhdc Word 1 03-30-2012 04:56 AM
Splitter Macro for Word 2007 Runtime Error 4120 in Word 2007 macro Frankwlc Word 5 11-28-2011 01:54 AM
*Word 2007 Macro for Character Count gbartlet Word 0 07-21-2010 11:12 AM
Please help with a macro in Microsoft Word 2007 AKMMS Word VBA 0 06-23-2010 02:16 PM
Word 2003 macro to Word 2007 to 2010 to... maruapo Word VBA 0 06-04-2010 03:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:22 AM.


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