James Niven
03-23-2016, 12:42 PM
Hi All,
I am looking for a little assistance here. I found the following code online that splits my word document into separate files, of one page. As you can see the file name for each document is "Test_1". What I want help with is the first row of each page has a line with a code. I want to use this as the file name when I convert all these pages as JPEG files. How do I change the code to do this?
Thanks
Sub BreakOnPage()
Dim I As Integer
Dim DocNum As Integer
Application.ScreenUpdating = False
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage
For I = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("\page").Range.Copy
' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "U:\Test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".jpeg"
ActiveDocument.Close
' Move the selection to the next page in the document.
Application.Browser.Next
Next I
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
End Sub
I am looking for a little assistance here. I found the following code online that splits my word document into separate files, of one page. As you can see the file name for each document is "Test_1". What I want help with is the first row of each page has a line with a code. I want to use this as the file name when I convert all these pages as JPEG files. How do I change the code to do this?
Thanks
Sub BreakOnPage()
Dim I As Integer
Dim DocNum As Integer
Application.ScreenUpdating = False
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage
For I = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("\page").Range.Copy
' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "U:\Test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".jpeg"
ActiveDocument.Close
' Move the selection to the next page in the document.
Application.Browser.Next
Next I
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
End Sub