I generate a string by quering values in cells and then add the string to an email. The email doesn't open when i use my generated string by will work fine with any other string. I cant figure out what is wrong, please help!
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 SeekForJobsNotDone()
Call LoopSeekForJobsNotDone
emlUserName = CreateObject("Wscript.Network".UserName
'Get the email address
Email = "user@company.com"
'Message subject
Subj = "User Add/Delete 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
This procedure generates the string
Sub LoopSeekForJobsNotDone()
Msg = ""
Counter = 1
XCounter = 3
Range("Add_Start".Select
Msg = "Add "
Do Until XCounter = 15
Do Until ActiveCell.Offset(Counter, 0).Value = "end"
If ActiveCell.Offset(Counter, XCounter).Value = "" Then
Msg = Msg & " " & ActiveCell.Offset(Counter, 0).Value & ", " & ActiveCell.Offset(-1, XCounter).Value & ". " & vbCrLf
Counter = Counter + 1
Else
Counter = Counter + 1
End If
Loop
'Msg = Msg & vbCrLf
XCounter = XCounter + 1
Counter = 1
Loop
Msg = Msg & "Delete "
Counter = 1
XCounter = 3
Range("Delete_Start".Select
Do Until XCounter = 15
Do Until ActiveCell.Offset(Counter, 0).Value = "end"
If ActiveCell.Offset(Counter, XCounter).Value = "" Then
Msg = Msg & " " & ActiveCell.Offset(Counter, 0).Value & ", " & ActiveCell.Offset(-1, XCounter).Value & ". " & vbCrLf
Counter = Counter + 1
Else
Counter = Counter + 1
End If
Loop
'Msg = Msg & vbCrLf
XCounter = XCounter + 1
Counter = 1
Loop
End Sub
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 SeekForJobsNotDone()
Call LoopSeekForJobsNotDone
emlUserName = CreateObject("Wscript.Network".UserName
'Get the email address
Email = "user@company.com"
'Message subject
Subj = "User Add/Delete 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
This procedure generates the string
Sub LoopSeekForJobsNotDone()
Msg = ""
Counter = 1
XCounter = 3
Range("Add_Start".Select
Msg = "Add "
Do Until XCounter = 15
Do Until ActiveCell.Offset(Counter, 0).Value = "end"
If ActiveCell.Offset(Counter, XCounter).Value = "" Then
Msg = Msg & " " & ActiveCell.Offset(Counter, 0).Value & ", " & ActiveCell.Offset(-1, XCounter).Value & ". " & vbCrLf
Counter = Counter + 1
Else
Counter = Counter + 1
End If
Loop
'Msg = Msg & vbCrLf
XCounter = XCounter + 1
Counter = 1
Loop
Msg = Msg & "Delete "
Counter = 1
XCounter = 3
Range("Delete_Start".Select
Do Until XCounter = 15
Do Until ActiveCell.Offset(Counter, 0).Value = "end"
If ActiveCell.Offset(Counter, XCounter).Value = "" Then
Msg = Msg & " " & ActiveCell.Offset(Counter, 0).Value & ", " & ActiveCell.Offset(-1, XCounter).Value & ". " & vbCrLf
Counter = Counter + 1
Else
Counter = Counter + 1
End If
Loop
'Msg = Msg & vbCrLf
XCounter = XCounter + 1
Counter = 1
Loop
End Sub