+ Reply to Thread
Results 1 to 12 of 12

Attach files to email created in Mozilla Thunderbird using VBA

  1. #1
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Attach files to email created in Mozilla Thunderbird using VBA

    Dears,

    I am using the following code to create an email using VBA (my client is Thunderbird).

    I can create the email properly (destination, subject, etc), but I am struggling to attach files. I have checked Mozilla forums for command line syntax but no success.

    This is the code I am using:

    Sub test()
    sCmd = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird"
    Email = "[email protected]" 'fake email, change to a real one
    Subject = "Test message"
    Content = "Check this out"
    attch = "C:/anyfile.pdf" 'fake file name and path, change to a real one
    '
    sCmd = sCmd & " -compose " & Chr$(34) & "mailto:" & Email & "?"
    sCmd = sCmd & "subject=" & Chr$(34) & Subject & Chr$(34)
    sCmd = sCmd & "&attachment=" & Chr$(34) & "file:///" & attch & Chr$(34)
    sCmd = sCmd & "&body=" & Content
    Call Shell(sCmd, vbNormalFocus)
    End Sub

    As I said above, the email pops up properly filled, but no success in attaching the proper file.

    Thanks in advance.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    This worked for me.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    That was great AlphaFrog. It worked fine for me. Thanks a lot.

  4. #4
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    One more question: I am having some trouble with the content part. Every time it has a dash or comma it truncates the message from that point.

    For example: if define Content = "Check this out, this is a test" ou "Check this out - this is a test", the macro will create the email with only the "Check this out".

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    Wrap the text in single quotes.

    Content = "'Check this out, this is a test'"

  6. #6
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    It worked for the comma, but not for the dash. If I define

    Content = "'Check this out - this is a test.'"

    I will only get up to the "Check this out".

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    Wrap the text with double-quotes.
    In vba, use two consecutive double-quotes to represent one literal double-quote within the string.

    Content = """Check this out - this is a test"""

  8. #8
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    Once again, many thanks for your time.

    However, as I am trying to create an spreadsheet with an email automation involving more complex messages, I am giving up using command line and switching to CDO, which seems to give more flexibility to customize the message (HTML formatted, for example).

    Best regards.

  9. #9
    Registered User
    Join Date
    06-23-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    6

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    Before closing the issue, as a final remark, I am moving forward with the implementation using CDO and, so far, is going well. Another advantage is that I can send the email automatically. By using the command line I was able to open and fill an email, but I still have to hit "send" buttom, which is not much practical when dealing with dozens of emails. Anyway, thanks for the tips, AlphaFrog. This double-double quotes, which I was not aware of, is helping in the new path.

  10. #10
    Registered User
    Join Date
    01-23-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    MIS Office 2003
    Posts
    1

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    I've just found this tread and it works super good for me, but i have one question that i cannot find a answer.

    How can i use this code and attach not only one attachmend but numerous.

    Thanks in advance

  11. #11
    Registered User
    Join Date
    12-16-2015
    Location
    India
    MS-Off Ver
    2010
    Posts
    1

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    I tried excatly the same thing however I am getting an error message statis the File Doesnt Exists. Not sure what wrong I am doing or what is incorrect with my excel application. Can you suggest something that I have to cross chk or should be in my checklist which I may have missed

  12. #12
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Attach files to email created in Mozilla Thunderbird using VBA

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Email using Mozilla Thunderbird
    By Bronx in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2019, 01:04 AM
  2. Attach files created by macro to an email
    By JesseSingh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2016, 12:12 AM
  3. Attach multiple files to an email
    By startuga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 02:18 PM
  4. Application.GetOpenFilename, Attach files to Email, Move files, Delete Original.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2009, 12:11 AM
  5. Objecdt for Mozilla Thunderbird mails
    By rakeshplb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2009, 07:03 AM
  6. Modifing code to attach files to email
    By jat82nd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2007, 01:41 PM
  7. [SOLVED] How Do I attach a atachment to a VBA created email?
    By Dan Gardner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2005, 04:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1