Opening Other Programmes?

Ste_Moore01

Active Member
Joined
Jul 13, 2005
Messages
467
Is it possible to open other programmes using a macro in excel?

For example...
I was hoping to open Microsoft Access and Microsoft Word using a macro in Excel.

Is this possible?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Ste_mooore01,
Since both MSAccess and MSWord have VBA, you can access them directly from Excel. Any program without VBA and without API's you would have trouble with.

Here's an example of opening a word doc from excel.

Code:
    Dim WordApp As Object
    Set WordApp = GetObject("C:\test.doc")
    Word.Application.Visible = True

You will still need to learn the how to utilize these objects for each of the different programs. Using access will be pretty well be pretty well the same ot setup the connection.

HTH
Cal
 
Upvote 0
Good afternoon SteMoore01

This would do the trick:

Sub Test()
Dim OpenExe
OpenExe = Shell("c:\program files\microsoft office\office\winword.exe", 1)
End Sub

HTH

DominicB
 
Upvote 0
Thanks guys!

DominicB your code works well but I was hoping to open a specific word document. Is there any way of doing this as I'm hoping to copy data from Excel and paste it in a word document that is already saved. It is the same with the Access problem.
 
Upvote 0
Ste_Moore01

Cal's code shows you how to open a specific document.

It also shows how you can create a reference to the Word application object.

You would need this reference to do what you want.
 
Upvote 0
I'm quite new to the coding side of things.. I've only been doing it a few months and most of it still befuddles me.

I tried Cals code and it brings up a Run-time error 424 and says "Object Required"

Dominics code opens word but doesn't open a particular document.
 
Upvote 0
I think the error is just a typo.

Instead of this
Code:
Word.Application.Visible = True
It should be this.
Code:
WordApp.Application.Visible = True

In fact I don't think Cal's code quite works.

Try this.
Code:
Dim WordApp As Object
    Set WordApp = CreateObject("Word.Application")
    
    WordApp.Documents.Open "C:\test.doc"
    WordApp.Application.Visible = True
 
Upvote 0
Hi guys

As an aside, this piece of code will open a Word document (in this case c:\wordy.doc) using the users standard registered software for .doc files. Therefore if a user doesn't use microsoft but one of the alternative office suites using the .doc extension, it will open the relevant piece of software.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub Test()
ShellExecute 0, vbNullString, "wordy.doc", vbNullString, "c:\", 1
End Sub

HTH

DominicB
 
Upvote 0
That's brilliant Dominic!

It allows me to open any file in the programme I've got set to open it.

That's helped my a lot because now I can add buttons that open other files.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,203,052
Messages
6,053,225
Members
444,648
Latest member
sinkuan85

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