-
VBA - Convert multiple word docs to PDF with names pulling from word table contents
Greetings! I'm trying to update this macro so the PDF names pull from the tables within each word doc. I keep getting various errors, including 'object not defined.' I'm relatively new to VBA and am unsure what next steps to take to get this macro working.
Here's the range of text I want to pull from for the PDF file names:
Dim StrFilename AsString
Dim StrNm AsString
Dim StrCat AsString
StrNm = Split(ActiveDocument.Tables(1).Cell(5,1).Range.Text, vbCr)(0)
StrCat = Split(ActiveDocument.Tables(1).Cell(2,1).Range.Text, vbCr)(0)
StrFilename = StrCat &"_"& StrNm &".pdf"
I've been trying to insert the naming rules into this multiple doc --> pdf macro that's working fine as is:
Sub ConvertDocmInDirToPDF()
Dim filePath AsString
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect =False
.Show
OnErrorResumeNext
filePath =.SelectedItems(1)
EndWith
If filePath =""ThenExitSub
If Right(filePath,1)<>""Then filePath = filePath &""
Application.ScreenUpdating =False
Dim currFile AsString
currFile = Dir(filePath &"*.docm")
DoWhile currFile <>""
Documents.Open (filePath & currFile)
Documents(currFile).ExportAsFixedFormat _
OutputFileName:=filePath & Left(currFile, Len(currFile)- Len(".docm"))&".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
From:=1,To:=1, Item:=wdExportDocumentContent, IncludeDocProps:=True, _
KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
Documents(currFile).Close
currFile = Dir()
Loop
Application.ScreenUpdating =True
EndSub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules