Open a desktop file path for any user

caramel_delight

New Member
Joined
Dec 24, 2020
Messages
4
Office Version
  1. 2011
Platform
  1. Windows
Hi All,

I am a beginer with codes so any help would be appreciated

I have the below code where i can import a module from my desktop. However, i want to module path so it can locate the files on any desktop and not just mine. But i cannot get it to work.

Anybody know what i am doing wrong



VBA Code:
Sub AutomateImport()
   
    Const ModulePath As String = "C:\Users\" & Environ("userprofile") & "\Desktop\EDIT\modupload.bas"
  
    Dim thisTarget As Workbook
    Dim thisName As String

    Set thisTarget = ActiveWorkbook
    thisName = thisTarget.Name

    ' Save as XLSM file (neceassry before importing module)
    ActiveWorkbook.SaveAs thisName & ".xlsm", _
      FileFormat:=xlOpenXMLWorkbookMacroEnabled

    ' Import the VBA code required
    thisTarget.VBProject.VBComponents.import ModulePath

    ' Save the workbook
    ActiveWorkbook.Save

End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,135
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Dim ModulePath As String
ModulePath = Environ("userprofile") & "\Desktop\EDIT\modupload.bas"
 

Watch MrExcel Video

Forum statistics

Threads
1,132,640
Messages
5,654,539
Members
418,139
Latest member
nimesh72

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
Top