VBA can't find path with attachment

Josu

New Member
Joined
Mar 2, 2021
Messages
39
Office Version
  1. 2010
Platform
  1. Windows
Hello, I am trying to add one file with vba macro and for this use path from excel sheet in cell B24
Basically I am trying to add C:\Users\%userprofile%\AppData\Local\Temp\Test.zip as this file will be used by multiple users
If I put my user name in path instead of %userprofile% attachment works
How I can trick this path to make sure that any user can use this macro?

VBA Code:
   With OutMail
        
        .To = ThisWorkbook.Sheets("Settings").Range("B15").Value
        .CC = ""
        .BCC = ""
        .Subject = ThisWorkbook.Sheets("Settings").Range("B18").Value
        .HTMLBody = strbody1 & signature
        '.Attachments.Add ActiveWorkbook.Sheets("Settings").Range("B24").Value
        .Display
        ActiveInspector.CommandBars.ExecuteMso ("CheckNames")
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If it is just the username then maybe try
VBA Code:
"C:\Users\" & Environ("username") & "\AppData\Local\Temp\Test.zip"
 
Upvote 0
If it is just the username then maybe try
VBA Code:
"C:\Users\" & Environ("username") & "\AppData\Local\Temp\Test.zip"
Thanks, I managed find in google some magic
I put path newPath = Environ("USERPROFILE") & "\AppData\Local\Temp\test.zip"
and
.Attachments.Add newPath
 
Upvote 0

Forum statistics

Threads
1,215,124
Messages
6,123,184
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top