PDA

View Full Version : Split 300 pg word doc into 2 docs



mazwoz
03-02-2009, 08:55 AM
I need a macro that will take every 4th page and cut it into a second doc that is not closed until after the macro is finished with the first doc. I get reports that are 300+ pages long and i have to take every 4th page and put it into a new doc. Can someone please help me with this, i am very new to VBA. Thanks

fumei
03-02-2009, 10:19 AM
Try recording a macro to take one page and copy it over to a new document. Once you get that, post it and we can help you adjust it.

It will need fairly serious adjustment because of the way Word looks at "pages". Pages are not real things to Word, so it can be a little tricky. But start with a simple macro to get one page, and we can move on from there.

mazwoz
03-02-2009, 11:58 PM
Thank you, but just before i saw your reply i figured it out.

fumei
03-03-2009, 09:39 AM
Then please post what you figured out. It may help others.

mazwoz
03-03-2009, 11:41 PM
For anyone that needs it, here is the code i used. It works!!!


Sub cutevery4th()



Dim iCurrentPage As Integer

Dim iPageCount As Integer

Dim docSingle As Document

Dim docMultiple As Document

iCurrentPage = 1

Set docMultiple = ActiveDocument

iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticPages)

Set docSingle = Documents.Add

Application.WindowState = wdWindowStateMinimize

docMultiple.Activate

Do Until iCurrentPage > iPageCount

If iCurrentPage = iPageCount Then

docSingle.Activate

Else

Selection.MoveDown Unit:=wdScreen, Count:=6

Selection.MoveDown Unit:=wdScreen, Count:=2, Extend:=wdExtend

Selection.Cut

docSingle.Activate

Application.WindowState = wdWindowStateNormal

Selection.PasteAndFormat (wdPasteDefault)

Application.WindowState = wdWindowStateMinimize

docMultiple.Activate

End If

Loop

End Sub


if someone knows a better way, please feel free to let me know.