Vba 在outlook中创建电子邮件时绕过255个字符的计数
我有下面的VBA,一旦它有时间在电子邮件中的描述字段,它就会停止。我已经研究过了,似乎有255个字符的限制。如何解决根据变量输入获取无限多个字符的问题Vba 在outlook中创建电子邮件时绕过255个字符的计数,vba,excel,outlook,Vba,Excel,Outlook,我有下面的VBA,一旦它有时间在电子邮件中的描述字段,它就会停止。我已经研究过了,似乎有255个字符的限制。如何解决根据变量输入获取无限多个字符的问题 Private Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters
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
Sub GenerateVolumeQuoteEMail()
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Dim r As Integer, x As Double
For r = 4 To 4 'data in rows 2-4
' Get the email address
' Email = Cells(r, 6)
' Message subject
Subj = "Volume Rate Request"
' Compose the message
Msg = ""
Msg = Msg & "UTS Order ID: " & Cells(r, 12) & vbCrLf & vbCrLf
Msg = Msg & "Shipping Adress: " & Cells(r + 1, 12) & vbCrLf & vbCrLf
Msg = Msg & "Consignee Adress: " & Cells(r + 2, 12) & vbCrLf & vbCrLf
Msg = Msg & "Description: " & Cells(r + 3, 12) & vbCrLf & vbCrLf
Msg = Msg & "Hazmat (Yes or No): " & Cells(r + 4, 12) & vbCrLf & vbCrLf
Msg = Msg & "Skid Count: " & Cells(r + 4, 12) & vbCrLf & vbCrLf
Msg = Msg & "Weight (in LBS): " & Cells(r + 6, 12) & vbCrLf & vbCrLf
Msg = Msg & "Class: " & Cells(r + 7, 12) & vbCrLf & vbCrLf
Msg = Msg & "Dimensions: " & Cells(r + 8, 12) & vbCrLf & vbCrLf
Msg = Msg & "Stackable: " & Cells(r + 9, 12) & vbCrLf & vbCrLf
Msg = Msg & "Special Requirements: " & Cells(r + 10, 12) & vbCrLf & vbCrLf
' 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"
Next r
End Sub
请帮助我,因为我仍在学习。如果@scraappy是正确的,并且您的问题仅仅是由于工作表功能的限制造成的
替换
,那么您可以通过替换适当的行轻松避免这些问题
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
使用替换:
Subj = Replace(Subj, " ", "%20")
Msg = Replace(Msg, " ", "%20")
Msg = Replace(Msg, vbCrLf, "%0D%0A")
255个字符的限制在哪里?在消息体上?在主题线上?我还不明白。看一看:到底哪一行引起了错误?VBA字符串可以远远超过255个字符,但Excel中的单元格不能。不要使用<代码> WorkStEffice。使用< <代码> >,使用<代码> VBA。字符串。替换“< /代码>”。也考虑使用Outlook对象模型,而不是使用<代码> SeulExcX//Cord> @拉尔夫,这正是我所想的。在我看来,将工作表函数用于VBA本机所做的事情从来都不是一个好主意。