Reply
 
Thread Tools Display Modes
  #1   Report Post  
MMSAK MMSAK is offline
Junior Member
 
Posts: 0
Question Please help with a macro in Microsoft Word 2007

I need help with the macro at the bottom of this post.

This macro is supposed to take a large Word document and save each page as a new, separate file.

The master file I am trying to separate is 213 pages. When I run the macro, it generates 213 new files, but the problem is that each new file it generates is the first page of the master file. In other words, all 213 new files are exactly the same.

Does anyone know why this would happen? What in the macro would cause it to create 213 copies of page 1 instead of 1 copy of each of the 213 pages in the master file?

Thanks in advance!

---


Sub SavePagesAsDoc()

Dim orig As Document
Dim page As Document
Dim numPages As Integer
Dim idx As Integer
Dim fn As String


' Keep a reference to the current document.
Set orig = ActiveDocument

' Calculate the number of pages
numPages = ActiveDocument.Range.Information(wdActiveEndPageNu mber)

For idx = 1 To numPages
' Make sure the document is active
orig.Activate

' Go to the page with index idx
Selection.GoTo What:=wdGoToPage, Name:=idx

' Select the current page
Selection.GoTo What:=wdGoToBookmark, Name:="\page"

' Copy the selection
Selection.Copy

' Create a new document
Set page = Documents.Add

' Activate it
page.Activate

' Paste the selection
Selection.PasteAndFormat wdFormatOriginalFormatting

' Generate the file name
fn = "Page" + CStr(idx) + ".doc"

' Save the document as Word 97-2003
page.SaveAs FileName:=fn, FileFormat:=wdFormatDocument, AddToRecentFiles:=False

' Close the document
page.Close

Next

End Sub
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Word 07 Macro problem Melvin Microsoft Word Help 0 January 11th 10 09:06 AM
Recording a macro to insert a Microsoft Graph Chart aeddave New Users 0 April 1st 09 08:52 PM
Cannot save "Microsoft Office Word 2007 Macro-enabled Document" d33pestblue Microsoft Word Help 1 July 30th 08 06:24 PM
Create Macro in Microsoft Word Fred Microsoft Word Help 0 October 25th 07 03:19 PM
How do you assign macro to toolbar button in microsoft word 2003 Trebormac Microsoft Word Help 2 October 26th 05 03:18 PM


All times are GMT +1. The time now is 11:00 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"