kengooch
Member
- Local time
- Today, 10:09
- Joined
- Feb 29, 2012
- Messages
- 137
I am trying to attach the current workbook to an email, but when I use the method shown online, it replaces the spaces with %20. I tried building the name and attaching it using the built name but get an error on that. Here is my code. Any suggestions or help would be greatly appreciated.
So if I build the name with vPath and then incorporate it into the vFilename, the debug.print shows the file name correctly, but the system errors out. If I use the ThisWorkbook.FullNameURLEncoded command it works and attaches the workbook, but it attaches the file as "20220808-Wk33%20Nurse%20Accomplishments%20for%20KGooch.xlsm"
I've read several posts, but none of them have worked.
Code:
With vMailItm
'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
.To = "Person1@va.gov; Person2@va.gov"
.CC = "Person3@va.gov"
.BCC = ""
.Subject = "Nurse-" & vFName & " " & vLName & " Accomplishment Tracker v." & Right(vVersn, 2) & " for " & Format(vDate, "yyyymmdd")
'* * * * * * Code with issue below * * * * * *
' .Attachments.Add ("ThisWorkbook." & vFileName) 'Trying to use the built name
.Attachments.Add (ThisWorkbook.FullNameURLEncoded) 'This line produces the string with %20 symbols, but it at least attaches the email
'* * * * * * End Code with issue * * * * * *
.HTMLBody = "<html>Dear Kim," & _
"<p>Here is my weekly Accomplishments Tracker Workbook for " & vDate & "." & "</p>" & _
"<p>Sincerely," & "<br>" & Mid(Application.UserName, InStr(Application.UserName, " ") + 1, Len(Application.UserName) - InStr(Application.UserName, " ")) & " " & vLName & "</p>" & _
"</body></html>"
MsgBox "! ! ! Please be sure to Encrypt the email before sending ! ! !" _
& vbCrLf & "Please use the [ Encrypt Only ] Option DO NOT USE S/_MIME" _
& vbCrLf + vbCrLf & "You can also add your signature line if you have created one by clicking the [Signature] Button on the Ribbon in the [Include] group. Then hit the send button" & _
vbCrLf + vbCrLf & "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" & _
vbCrLf & " Please Do Not Change the Subject Line of this Email!!" & vbCrLf & _
"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" & vbCrLf + vbCrLf & _
" Thanks for all that you did today!", vbOKOnly + vbInformation
So if I build the name with vPath and then incorporate it into the vFilename, the debug.print shows the file name correctly, but the system errors out. If I use the ThisWorkbook.FullNameURLEncoded command it works and attaches the workbook, but it attaches the file as "20220808-Wk33%20Nurse%20Accomplishments%20for%20KGooch.xlsm"
I've read several posts, but none of them have worked.