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:
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.
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