I found some code on these forums, it worked well until it started to crash excel. It crashes on the line starting "ShellExecute", i'm wondering if the string is too big. Please help as this project is urgent!
Thankyou in advance
SgtPepps
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Dim emlUserName As String
Sub Procedure()
emlUserName = CreateObject("Wscript.Network".UserName
'Get the email address
Email = "user@company.com"
'Message subject
Subj = "Update from" & emlUserName
'Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20"
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20"
'Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A"
'Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
'Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
'Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:02")
Application.SendKeys "%s"
End Sub
Thankyou in advance
SgtPepps
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Dim emlUserName As String
Sub Procedure()
emlUserName = CreateObject("Wscript.Network".UserName
'Get the email address
Email = "user@company.com"
'Message subject
Subj = "Update from" & emlUserName
'Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20"
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20"
'Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A"
'Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
'Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
'Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:02")
Application.SendKeys "%s"
End Sub