Using VBA in Excel to Combine Multiple Word Files to Single PDF

agent_maxine

New Member
Joined
Aug 23, 2017
Messages
38
Kindly requesting your help on this topic...
I have an Excel file that generates multiple Word documents. I am trying to accomplish the following:


  • From Excel, a file dialogue opens up for users to select multiple files (Word & PDF files)
  • All the selected files are printed/merged into a single PDF file
  • The combined PDF file is saved in the same folder as the original Excel file, with the name "All Files"

Error Message = "Run-time error 4248: This command is not available because no document is open."

I realize the codes are very incomplete... not sure how to fix it though.

Code:
Sub Merge_Documents_PDF()

Dim intChoice As Integer

'Select the Start Folder. File Dialog becomes Visible to the User
Application.FileDialog(msoFileDialogOpen).InitialFileName = Application.ActiveWorkbook.Path & "\Forms\"
intChoice = Application.FileDialog(msoFileDialogOpen).Show

'Determine what Choice the User made
If intChoice <> 0 Then

    Dim wordFile As Object
    Set wordFile = CreateObject("Word.Application")

    wordFile.ActiveDocument.ExportAsFixedFormat Type:=wdExportFormatPDF, FileName:= _
    wordFile.ActiveDocument.Path & "\" & fichierWord.ActiveDocument.Name & ".pdf"

Else
    
    MsgBox "No Files were selected."

End If

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,215,454
Messages
6,124,931
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top