caramel_delight
New Member
- Joined
- Dec 24, 2020
- Messages
- 4
- Office Version
- 2011
- Platform
- 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
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