Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2010, 02:16 PM
AKMMS AKMMS is offline Please help with a macro in Microsoft Word 2007 Windows XP Please help with a macro in Microsoft Word 2007 Office 2007
Novice
Please help with a macro in Microsoft Word 2007
 
Join Date: Jun 2010
Posts: 1
AKMMS is on a distinguished road
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 With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2003 macro to Word 2007 to 2010 to... maruapo Word VBA 0 06-04-2010 03:43 PM
Inserting citations using the reference function in Microsoft Word 2007? aeyara Word 0 09-28-2009 05:33 PM
microsoft outlook 2007 and roaming marko959 Outlook 0 06-03-2009 10:16 AM
Please help with a macro in Microsoft Word 2007 Microsoft ofc 2007 anu Office 1 05-23-2009 10:40 AM
Microsoft Office 2007 riptorn Office 1 11-30-2008 06:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:35 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