Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-04-2014, 11:42 AM
vbAMEN vbAMEN is offline Exporting .doc as .pdf Not A Valid File Name Windows 7 32bit Exporting .doc as .pdf Not A Valid File Name Office 2010 32bit
Novice
Exporting .doc as .pdf Not A Valid File Name
 
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
  #2  
Old 06-05-2014, 04:20 AM
macropod's Avatar
macropod macropod is offline Exporting .doc as .pdf Not A Valid File Name Windows 7 32bit Exporting .doc as .pdf Not A Valid File Name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something along the lines of:
Code:
Dim DocCount As Long, MaxDocs As Integer, DocName As String
With ActiveDocument
  .Repaginate
  MaxDocs = .Sections.Count
  For DocCount = 1 To MaxDocs
    With .Sections(DocCount).Footers(wdHeaderFooterPrimary).Range
      DocName = Trim(Left(Replace(.Text, vbCr, " "), Len(Replace(.Text, vbCr, " ")) - 47)) & ".pdf"
    End With
    .ExportAsFixedFormat OutputFileName:=.Path & "\" & DocName, ExportFormat:=wdExportFormatPDF, _
      OpenAfterExport:=False, Range:=wdExportFromTo, From:=DocCount * 2 - 1, To:=DocCount * 2, _
      OptimizeFor:=wdExportOptimizeForPrint, Item:=wdExportDocumentContent, IncludeDocProps:=True, _
      CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, _
      KeepIRM:=True, UseISO19005_1:=False
  Next DocCount
End With
Note: It's possible your errors are due to the footer text length not being more than the 47 characters you're trying to reduce it by. With the code you had, it was also possible you were including one or more paragraph breaks in the prospective filename.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-09-2014, 08:14 AM
vbAMEN vbAMEN is offline Exporting .doc as .pdf Not A Valid File Name Windows 7 32bit Exporting .doc as .pdf Not A Valid File Name Office 2010 32bit
Novice
Exporting .doc as .pdf Not A Valid File Name
 
Join Date: Jun 2014
Posts: 2
vbAMEN is on a distinguished road
Default

Thanks, I tried this code and I got the same error.
I don't understand why I'm getting this error when I hover on the variable docname, it looks like a valid file name.
Reply With Quote
  #4  
Old 06-09-2014, 04:09 PM
macropod's Avatar
macropod macropod is offline Exporting .doc as .pdf Not A Valid File Name Windows 7 32bit Exporting .doc as .pdf Not A Valid File Name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by vbAMEN View Post
Thanks, I tried this code and I got the same error.
I don't understand why I'm getting this error when I hover on the variable docname, it looks like a valid file name.
Evidently, though, it isn't. Unless you can provide details of what's being fed into the DocName variable, progress is unlikely.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting images with correct file names lister PowerPoint 1 03-12-2014 12:27 AM
Exporting/printing MS Project File containing Gantt Chart to an Image ms_user Project 7 04-02-2013 02:50 AM
Exporting .doc as .pdf Not A Valid File Name Exporting multiple calendars to CSV file sharke Outlook 2 09-06-2010 07:40 PM
Exporting to PDF and keeping file size down CloudandBanner Word 0 08-24-2009 09:29 AM
Outlook 2003 drops notes when exporting as a VCARD file GY58 Outlook 0 04-29-2006 07:57 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft