Consulting

Results 1 to 5 of 5

Thread: email & attachment word doc.

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    email & attachment word doc.

    Hi I have the below code that I use for sending an email automatically. I would like to adapt it to include a Word Doc as an attachment to this email. The Doc. will be kept in the same folder as the workbook.

    [vba]Dim Email_Subject, Email_Send_From, Email_Send_To, _
    Email_Cc, Email_Bcc, Email_Body As String
    Dim Mail_Object, Mail_Single As Variant
    Email_Subject = ""
    Email_Send_From = ""
    Email_Send_To = ""
    Email_Cc = ""
    Email_Bcc = ""
    Email_Body = "Test only"
    On Error GoTo debugs
    Set Mail_Object = CreateObject("Outlook.Application")
    Set Mail_Single = Mail_Object.CreateItem(0)
    With Mail_Single
    .subject = Email_Subject
    .To = Email_Send_To
    .cc = Email_Cc
    .BCC = Email_Bcc[/vba]


    What else can I put into this to attach the word doc in the same folder automatically?

  2. #2
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    Is there a
    .add.attchment.word.doc name Same path as saved file possibility?

  3. #3
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    I would have thought it would be like this...
    [VBA].Attachments.Add ThisWorkbook.Path & "\" & "FileName.doc"[/VBA]
    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  4. #4
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    Hi Georgiboy, it seems I have your code working. But have one other issue. If the attachment in not there I get an error. Is there a way to resolve this that is attachment is not there continue...?

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    [VBA]'workbook is already saved and has a name
    'no . are used in the naming for files
    If InStr(ThisWorkbook.Name, ".") > 0 Then
    'check if a file exists in this directory
    If Dir(ThisWorkbook.Path & Application.PathSeparator & _
    Split(ThisWorkbook.Name, ".")(0) & ".doc") <> vbNullString Then
    MsgBox Split(ThisWorkbook.Name, ".")(0) & ".doc is found."
    Else
    MsgBox Split(ThisWorkbook.Name, ".")(0) & ".doc not found."
    End If
    Else
    MsgBox "Save your workbook first."
    End If[/VBA]Charlize

Posting Permissions

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