View Single Post
 
Old 06-04-2014, 11:42 AM
vbAMEN vbAMEN is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Jun 2014
Posts: 2
vbAMEN is on a distinguished road
Default Exporting .doc as .pdf Not A Valid File Name

I am trying to split a document by every 2 pages and name the files using the text from the footer, but I keep getting an error saying it is not a valid filename. There are no special characters in the footer and when I hardcode the same text as a filename into the DocName variable, it works just fine. Any help would be appreciated. Here is my code:

Dim PageCount As Integer
Dim DocCount As Integer
Dim NextPage As Integer
Dim MaxDocs As Integer
Dim DocName, ftStr As String

ActiveDocument.Repaginate
MaxDocs = (ActiveDocument.BuiltInDocumentProperties(wdProper tyPages)) / 2
PageCount = 1


For DocCount = 1 To MaxDocs

ftLen = Len(ActiveDocument.Sections(DocCount).Footers(wdHe aderFooterPrimary).Range)
ftStr = Trim(Left(ActiveDocument.Sections(DocCount).Footer s(wdHeaderFooterPrimary).Range.Text, ftLen - 47)) & ".pdf"

NextPage = PageCount + 1

DocName = CStr(ftStr)

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
ActiveDocument.Path & "\" & DocName, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=PageCount, To:=NextPage, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

PageCount = PageCount + 2

Next DocCount
Reply With Quote