jbndylan
asked on
How can I truncate a footer to the first 15 characters? Word 2010 vba
I am splitting a word document with multiple letters to individual files. The text I want to use as the filename is in the first 14 characters of the footer.
I need to truncate the footer to name the files.
I am very new to vba, any help would be greatly appreciated.
Below is my code :
I need to truncate the footer to name the files.
I am very new to vba, any help would be greatly appreciated.
Below is my code :
Sub BreakOnPVOHSection()
Dim letter As Range
Dim fname As Range
Dim target As Document
Dim strFileName As String
Dim strID As String
' Used to set criteria for moving through the document by section.
Application.Browser.target = wdBrowseSection
'A mailmerge document ends with a section break next page.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
Set fname = ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range
fname.End = fname.End - 1
'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
' ActiveDocument.Bookmarks = Mid(fname, 0, 12)
ChangeFileOpenDirectory "\\vcuhshmo\users\lheaton\bpa"
docnum = docnum + 1
ActiveDocument.SaveAs fileName:=fname.Text & ".docx"
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
' Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
ASKER
The naming works beautifully, thank you. But it's stripping out the header, footer and formatting that are needed. I will add those parts back in and see how it goes!!! Thank you so much for resolving this naming thing. Whew!
ASKER
I'm sorry. I was not clear regarding the header/footer. Those I want to keep. Only for the filename do I want to include the first 14 characters of the footer. The names your code came up with are perfect.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are my hero of heros!!!!!!!!!!!! I have been working on this forever. Thank you!!!!!!!!!!!!!!!!!
You are a genius!
You are a genius!
Open in new window