Results 1 to 7 of 7

Thread: VBA help to email a document

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Regular
    Joined
    Oct 2009
    Posts
    69
    Location
    Ok this is what i came up with but i'm getting error message "RUN TIME ERROR 424 - OBJECT REQUIRED" and when i hit debug it highlight this item in my code:

    TempFileName = "" & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

    Can someone please help me to fix this? Here is my entire code:

    Private Sub CommandButton21_Click()
    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document
    Dim TempFilePath As String
        
    Dim TempFileName As String
     
    Application.ScreenUpdating = False
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set Doc = ActiveDocument
    TempFilePath = Environ$("temp") & "\"
        
    TempFileName = "" & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
    Doc.SaveAs2 TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
     
    With EmailItem
        .Subject = "P66 Bayway Refinery Waste Collection Request Form"
        .Body = "Please see attached form"
        .To = ***@gmail.com
        
        '.cc = ""
        '.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
        .Attachments.Add Doc.FullName
        .Send
    End With
     
    Application.ScreenUpdating = True
     
    Set Doc = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
    MsgBox "Your form has been emailed. Please check your sent item for a copy"
    ThisDocument.Close SaveChanges:=False
         
    End Sub
    Last edited by megha; 11-09-2017 at 10:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •