Macro to open the file selector select a document to open then run a macro

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
so i need a bit of help with this complex macro

I want to be able to have a macro that does this

the macro is contained in its own documet along with another called update.
when we run the macro it does this.
opens the file explore and asks the user to select the document they wish to open,
if possible check the selected document is xlsm
open the document (it will need the password "Password1234"
then run the othe macro "update" on the opened document and save it.

please help if you can

thabks

tony
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This worked for me. You'll need to update the drive letter and drive paths in order for the macro to navigate directly to your preferred folder.

VBA Code:
Sub OpenFileRunMacro()

'Declare Variables
Dim objExcel       As Object
Dim objMacro       As Object
Dim strMacroFile   As String
Dim varFileName    As Variant

Const STRDRIVELETTER As String = "C:"
Const STRDRIVEPATH As String = "\Example Folder\Subfolder"
Const STRFILTERS As String = "Excel Files (*.xlsm),*.xlsm,"

'Change Drive To Desired Folder Location
ChDrive STRDRIVELETTER
ChDir STRDRIVELETTER & STRDRIVEPATH

'Prompt User To Identify File With Macro To Run
varFileName = Application.GetOpenFilename _
   (FileFilter:=STRFILTERS, _
   FilterIndex:=1, _
   MultiSelect:=False)
strMacroFile = varFileName

'Open Macro File
Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

'Run Macro
Set objMacro = objExcel.Workbooks _
   .Open(Filename:=strMacroFile, ReadOnly:=False)


objExcel.Run "HellWorld"

objMacro.Save
objMacro.Close

Set objExcel = Nothing
Set objMacro = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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