Hi everyone,
I wonder if someone can help me. Ive scoured the internet for an answer to what I believe is a simple task but cannot find anything that matches my requirements at all.
Basically I have a document which is created from SharePoint using my Mailmerge web part. This creates 1x Word document with currently 100 pages.
I have written a macro to resave this 100page document into 100 separate 1x page documents and to automaticall convert them to .txt files.
However, they currently are called 'Document_1.txt ', 'Document_2.txt ' etc etc
What I am trying to achieve is to take either the value of the header of the document or a string found in the document and use this string as the filename of document when saved so every document would have a different filename, e.g 'Reading Policy.txt', 'Writing Policy.txt' etc.
The code I currently have is:
The text that I want to use to name my documents is ALWAYS on the same line in each word document (once parsed into separate documents). That is line 10 and inbetween the text <Value> and </Value>
Can somebody help me with the extra code I need to do this please?
Rick Lister
I wonder if someone can help me. Ive scoured the internet for an answer to what I believe is a simple task but cannot find anything that matches my requirements at all.
Basically I have a document which is created from SharePoint using my Mailmerge web part. This creates 1x Word document with currently 100 pages.
I have written a macro to resave this 100page document into 100 separate 1x page documents and to automaticall convert them to .txt files.
However, they currently are called 'Document_1.txt ', 'Document_2.txt ' etc etc
What I am trying to achieve is to take either the value of the header of the document or a string found in the document and use this string as the filename of document when saved so every document would have a different filename, e.g 'Reading Policy.txt', 'Writing Policy.txt' etc.
The code I currently have is:
Code:
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:\Documents and Settings\Administrator\Desktop\UploadXML"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Document_" & DocNum & ".txt", FileFormat:=wdFormatText
ActiveDocument.Close
' Move the selection to the next page in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
The text that I want to use to name my documents is ALWAYS on the same line in each word document (once parsed into separate documents). That is line 10 and inbetween the text <Value> and </Value>
Can somebody help me with the extra code I need to do this please?
Rick Lister
Comment