Excel VBA code to open other applications

squeakums

Well-known Member
Joined
May 15, 2007
Messages
851
Office Version
  1. 365
I was trying to find code in excel macros that can open other apps for example, open Access DB and run a macro in it.

Also,

Open Google Chrome and go to a link.

I tried several codes I found online but those didn't seem to work for me. Any advice?

Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
works for me...

VBA Code:
Sub Chrome()
    Dim WebUrl As String
    WebUrl = "https://www.google.co.uk/"
    Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & WebUrl)
End Sub
 
Upvote 0
I was trying to find code in excel macros that can open other apps for example, open Access DB and run a macro in it

Linked video below explains clearly how to use VBA in Excel to Extract Data from an Access Database and place that data in a worksheet

 
Upvote 0
Two ways of opening Access and running a macro:

VBA Code:
Sub OpenAccess()
    With New Access.Application
        .OpenCurrentDatabase "C:\MyDBase.accdb"
        .Visible = True
        .DoCmd.RunMacro "MyMacro"
'If you want to close it when done...
        .CloseCurrentDatabase
    End With
End Sub

Sub ShellAccess()
    Dim Arg As String
    Arg = "C:\MyDBase.accdb /X MyMacro"
    Shell "C:\Program Files\Microsoft Office\root\Office16\MSAccess.exe " & Arg
End Sub
 
Upvote 0
For the first code above I get that annoying "user defined type not defined" ? When I run at this part:
Sub OpenAccess()
With New Access.Application
 
Upvote 0
For the first code above I get that annoying "user defined type not defined" ?

That is because VBA has not been told how to read Access commands
It's illustrated in the video linked in post#3 -which is worth watching to help you understand the code provided by @Paul Ked

In VBA \ click on Tools \ References\ Scroll down to Microsoft Access object library\ Tick the box \ OK
 
Upvote 0
That is because VBA has not been told how to read Access commands
It's illustrated in the video linked in post#3 -which is worth watching to help you understand the code provided by @Paul Ked

In VBA \ click on Tools \ References\ Scroll down to Microsoft Access object library\ Tick the box \ OK

Thank you past that part, now getting the error, already have the database open? And, I don't?
 
Upvote 0
1574779510514.png
 
Upvote 0

Forum statistics

Threads
1,224,647
Messages
6,180,147
Members
452,966
Latest member
Daniel Moussavou

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