Hi there,
I'm looking to take a document, and save each page as a separate Word doc. I lifted the code from Word's website to split the document, so that's fine. However, I'd like to name each page based on a textbox within the document, and I'm not sure how to do that. Is it easier to:
(a) copy text from a textbox (and how do i copy that text) and into the string
(b) "find" the text (what I'm looking for will always be in format "___ Price") and copy into the string
(c) copy the text from the header and into a string
The code in question in bolded below. Appreciate your help!!
Cheers,
-----------
Sub BreakOnPage()
' 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 "C:"
DocNum = DocNum + 1
Dim Price As String
price = ActiveDocument.Shapes("textbox1").Text
ActiveDocument.SaveAs FileName:=& price & ".doc"
ActiveDocument.Close
' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
I'm looking to take a document, and save each page as a separate Word doc. I lifted the code from Word's website to split the document, so that's fine. However, I'd like to name each page based on a textbox within the document, and I'm not sure how to do that. Is it easier to:
(a) copy text from a textbox (and how do i copy that text) and into the string
(b) "find" the text (what I'm looking for will always be in format "___ Price") and copy into the string
(c) copy the text from the header and into a string
The code in question in bolded below. Appreciate your help!!
Cheers,
-----------
Sub BreakOnPage()
' 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 "C:"
DocNum = DocNum + 1
Dim Price As String
price = ActiveDocument.Shapes("textbox1").Text
ActiveDocument.SaveAs FileName:=& price & ".doc"
ActiveDocument.Close
' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub