Solved Attach current Workbook to an Email. (1 Viewer)

kengooch

Member
Local time
Today, 09: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.
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:09
Joined
Sep 21, 2011
Messages
14,291
Why not just use the filename, period?
 

kengooch

Member
Local time
Today, 09:09
Joined
Feb 29, 2012
Messages
137
I've tried it. That is what the first line does that I have commented out. It tells me the file is already open and can't be accessed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:09
Joined
Sep 21, 2011
Messages
14,291
Well, no, you would need to close the file? :(
Why the prefix of Thisworkbook?, changing the name will not affect that unless you have saved a copy as that name?
I take it you are running this code from the file you are trying to attach?
 

Users who are viewing this thread

Top Bottom