Hi,
have this code and giving run-time error 424 object required and highlight this line
complete code:
thank you
have this code and giving run-time error 424 object required and highlight this line
VBA Code:
ProgressBox.Show
VBA Code:
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare PtrSafe Function CoAllowSetForegroundWindow Lib "ole32.dll" (ByVal pUnk As Object, ByVal lpvReserved As Long) As Long
Dim Namespace As Namespace
Dim FileSystemObject As FileSystemObject
Dim SelectedEmails As Selection
Dim SavedFiles As Collection
Dim FilesToMerge As Collection
Dim WordApp As Word.Application
Dim ExcelApp As Excel.Application
' Regular expressions defining the attachments that will be processed.
' All other attachments will be ignored.
Const ExcelExtensionsRegExp = "^(xl(s|sx|sm|t|tm|tx))$"
Const ImageExtensionsRegExp = "^(jpg|jepg|png|gif|bmp|tiff?)$"
Const OtherExtensionsRegExp = "^(do(c|cx|cm|t|tm|tx)|pdf|txt)$"
Const MessageExtensionsRegExp = "^(msg)$"
Sub ExportToPdf()
' Exit if the user has not selected at least one email.
If (Outlook.ActiveExplorer.Selection.Count = 0) Then
MsgBox "Please select one or more emails.", vbInformation + vbOKOnly
Exit Sub
End If
Set Namespace = Application.GetNamespace("MAPI")
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set SelectedEmails = Outlook.ActiveExplorer.Selection
Set SavedFiles = New Collection
Set FilesToMerge = New Collection
Set WordApp = New Word.Application
WordApp.Visible = False
' Allow Word to take focus. Required to ensure the Save As dialog comes to the foreground.
CoAllowSetForegroundWindow WordApp, 0
' Backup the "warn before saving" option.
WarnBeforeSaveOption = WordApp.Options.WarnBeforeSavingPrintingSendingMarkup
' Disable the option.
WordApp.Options.WarnBeforeSavingPrintingSendingMarkup = False
Set ExcelApp = Nothing
' The path where the generated PDF will be saved.
PdfPath = GetPdfPath
' Exit if no path is specified for saving the PDF.
' This will occur if the user closes the 'File Save As' dialog without providing a valid path.
If PdfPath = "" Then
' Word is used to display the 'File Save As' dialog.
' Close Word before exiting.
WordApp.Quit
Exit Sub
End If
' The path to the folder where all temporary documents, and the final PDF, will be saved.
SavePath = Left(PdfPath, InStrRev(PdfPath, "\"))
' Initialise the progress bar component.
ProgressBox.Show
ProgressBox.Increment 0, "Exporting..."
' Save the selected emails, and their attachments, to the file system.
SaveEmails SelectedEmails, SavePath
' Convert each of the saved files to PDF documents.
ConvertDocumentsToPdf
' Merge the PDF documents into a single PDF document.
MergePdfDocuments PdfPath
' Indicate the export is complete.
ProgressBox.Increment 100, "Complete!"
' Show the completion dialog for 1 second.
Sleep 1000
ProgressBox.Hide
' Reinstate the old "warn before save" option.
WordApp.Options.WarnBeforeSavingPrintingSendingMarkup = WarnBeforeSaveOption
' Close Word (and Excel, if it was used to process attachments).
WordApp.Quit
If Not (ExcelApp Is Nothing) Then
ExcelApp.DisplayAlerts = True
ExcelApp.Quit
End If
' Clean up.
Set SavedFiles = Nothing
Set FilesToMerge = Nothing
Set SelectedEmails = Nothing
Set FileSystemObject = Nothing
Set Namespace = Nothing
End Sub
thank you