#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro fails to add image border in Word 2007 | samhdc | Word | 1 | 03-30-2012 04:56 AM |
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 |