Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats wrong with this string?

Status
Not open for further replies.

SgtPepps

IS-IT--Management
May 1, 2002
109
GB
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
 
I'm using Outlook express & office 2000
 
I believe that the string is just too big, or that there are too many 'vbCrLf' in there. I'm just going to adjust the crazy loop above to create a smaller string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top