RUN-TIME ERROR 424

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
784
Office Version
  1. 365
Hi,

have this code and giving run-time error 424 object required and highlight this line
VBA Code:
ProgressBox.Show
complete code:

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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Do you have a UserForm called "ProgressBox"?
 
Upvote 0
oh, thank you.

no that good in VBA just learning I created the userform but now giving another error "Method or data member no found" and
highlight this line:

VBA Code:
ProgressBox.Increment 0, "Exporting..."
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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