In excel I'm trying to insert a button to parse the contents of selected cells to a new email. Since I use Mozilla Thunderbird, I have to parse through Shell. My code so far:
Dim dr As String
If dir("C:\Program Files (x64)", vbDirectory) = "" Then
dr = "C:\Program Files (x86)"
Else
dr = "C:\Program Files"
End If
dr = dr & "\Mozilla Thunderbird\thunderbird.exe"
Dim args As String
args = "to='" & MailTo & "',cc='" & MailCC & "',bcc='" & MailBCC & "'"
args = args & ",subject='" & MailSubject & "',body='" & strbody & "'"
If MailBijlage <> "" Then args = args & ",attachment='" & TempFilePath & TempFileName & ".pdf"
Dim Command As String
Command = "cmd.exe /S /K " & """" & dr & """" & " -compose " & """" & args & """"
conf = MsgBox(Command, vbOKCancel, "Confirm command")
If conf = vbOK Then
Shell (Command)
MsgBox "Email sent.", , "Info"
ElseIf conf = vbCancel Then
MsgBox "Canceled.", , "Info"
End If
Creating the Command is handled well, but Shell won't start Thunderbird. It just says:
'C:\Program' is not recognized as an internal or external command, operatable program or batch file.
I don't know what's wrong, the message box showing the code clearly shows the double quotes around the path.
Thanks in advance.
==EDIT==
Trying to get it working using a batch file now (as suggested by S O)... I opened a bat file (which is created) and let VBA output commands to the bat-file. When I get to the point of the msgbox asking to send the mail, when I open the bat-file in notepad, it's empty. VBA calls the empty batch file and nothing happens (mail was not sent). When I reopen the file after the macro has ended, all output is in the batch file and when I run it, a mail is composed as it should.
Open Environ("userprofile") & "\desktop\tbmail.bat" For Output As #1
If dir("C:\Program Files (x64)", vbDirectory) = "" Then
Print #1, "cd ""%programfiles(x86)%"""
Else
Print #1, "cd ""%programfiles%"""
End If
Print #1, "cd ""Mozilla Thunderbird"""
Print #1, "thunderbird.exe -compose """ & args & """"
Close #1
If conf = vbOK Then
Call Shell(Environ("userprofile") & "\desktop\tbmail.bat")
MsgBox "De mail is verstuurd.", , "Informatie"
ElseIf conf = vbCancel Then
MsgBox "Versturen geannuleerd.", , "Informatie"
End If
What's wrong?