Solved

Access 97 – Activating Word, Excel or Power Point Without Knowing Their FilePath

Posted on 2002-05-21
23
253 Views
Last Modified: 2011-09-20
I have tried the following code but I get “File Not Found” error message if these Microsoft programs are not in filepath c:\Program Files\Microsoft Office\Office
(e.g. If User has upgraded from Office 97 to Office 2000)

Code Sample 1

Dim stAppName = “winword.exe c:\My Documents\myfile.doc”
Call Shell (stAppName,1)

Code Sample 2
Dim MyAppId
MyAppId = Shell(“winword.exe c:\My Documents\myfile.doc”,1)
AppActivate MyAppId

Do you have a code sample that will work regardless of where Excel, Word or Power Point .exe's are stored on a user's PC?
0
Comment
Question by:jazzman2
  • 11
  • 10
  • 2
23 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7025312
Hi, jazzman2

code above will work, if winword or any other is registered correclty on the pc
it will not work if the file myfile.doc or any other is not in my documents

so is the file there?and are the applications working correct?

HTH:O)Bruintje
0
 

Author Comment

by:jazzman2
ID: 7025330
Hi bruintje,

Yes all the Microsoft applications are working and myfile.doc is in folder c:\My Documents

jazzman2
0
 
LVL 2

Expert Comment

by:Bangerter
ID: 7025348
i use this type of call the open other programs:

Dim appExl As Excel.Application
Set appExl = New Excel.Application
appExl.Workbooks.Open "c:\Temp\MyFile.xls"

are you just trying to open Word or is there a file you want to have open up into Word?
0
 

Author Comment

by:jazzman2
ID: 7025376
Hi Bangerter

I am trying to open a specific .doc file in Word, a specific .xls file in Excel and a specific .ppt file in Power Point.

I am also trying to open Excel only.

Jazzman2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025457
Hi Jazzman2,

you say this is after upgrading, but is this now on a machine with two installations?
0
 

Author Comment

by:jazzman2
ID: 7025470
Hi bruintje,

Yes, the PC has both Office 97 and Office 2000

Jazzman2

0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025481
Hi Jazzman2,
ok then i guess the problem something like this

since 2000 is now the leading version, last installed but it seems not correctly registered in the registry

if you try to run this on the commandline for the word 2000 exe does that help?

regsvr32 yourpath\winword.exe

:O)Bruintje
0
 

Author Comment

by:jazzman2
ID: 7025495
Hi bruintje,

Word, Excel, Power Point 2000 all run fine on the client's PC ... they are all registered correctly.

My problem is I can't get them to start up with the two code examples I submitted with my question.

Do you have any other code that will work?

Thanks
Jazzman2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025535
HI Jazzman2,

Bangerter gave an example already how to start Excel, if you want otheres which are basically teh same say so and we'll come up with more

basically calling the apps like

Dim objApp as Object
Set objApp = CreateObject("App.Application")
objApp.Open ("Yourfile")
objApp.visible = true

will work for all of them

HTH:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025536
where App is Excel, Word etc...
0
 

Author Comment

by:jazzman2
ID: 7025584
Hi bruintje

I tried Bangerter's example and Access 97 gave me error message "User-defined type not defined"

I tried your example and Access 97 gave me error message "Object doesn't support this property or method"

Do you have any other suggestions?

Thanks
Jazzman2
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:Bangerter
ID: 7025602
for mine you will need to set the reference to the excel object library.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025607
Hi Jazzman2,

OK, so it looks like we got a registry problem

what about trying it two other ways just to make sure?

-first method
-in your access project in tools | references | add the excel object in your references
-then replace the code above

Dim objApp as Excel.Application
Set objApp = CreateObject("Excel.Application")
objApp.Open ("Yourfile")
objApp.visible = true < comes the error here?

-second method
-in your access project in tools | references | add the excel object in your references
-then replace the code above

Dim objApp as Excel.Application
Set objApp = CreateObject("Excel.Application.9")
objApp.Open ("Yourfile")
objApp.visible = true < comes the error here?

:O)Bruintje

0
 

Author Comment

by:jazzman2
ID: 7025670
Hi Bruintje,

I tried the following code after I added Microsoft Word 8.0 Object Library to my References

Dim objApp As Word.Application
    Set objApp = CreateObject("Word.Application")
    objApp.Open ("c:\My Documents\myfile.doc")
    objApp.Visible = True

Now I get error message "Method or data member not found" and my code halts on line objApp.Open

Jazzman2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7025684
OK, my fault

what about

Word
objApp.Documents.Open("c:\My Documents\myfile.doc")

Excel
objApp.Workbooks.Open("c:\My Documents\myfile.xls")

it's getting late
0
 

Author Comment

by:jazzman2
ID: 7025705
Hi Bruintje,

This worked but Word opens my file in a minimized window ... Is there a way to open Word in a Maximized Window like you can when you use the Shell function with ,1 after the filepath?

I still have to try your suggested code on my client's PC tomorrow to see if it works there.

Thanks
Jazzman2
0
 

Author Comment

by:jazzman2
ID: 7025824
Hi Bruintje,

I found a solution to Maximizing the Application.

I still have a problem with this code ...

Dim objApp As PowerPoint.Application
    Set objApp = CreateObject("PowerPoint.Application")
    objApp.Presentations.Open ("C:\My Documents\MyPresentation.ppt")
    objApp.Visible = True
    objApp.WindowState = ppWindowMaximized

I get this error message ... "Presentations (Unknown member):Invalid request. The PowerPoint Frame window does not exist."

Do you know why I'm getting this message?

Jazzman2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7026095
Hi Jazzman2,

seems like Powerpoint needs some extra care here

try to activate it so the window/frame becomes available.

Set objApp = CreateObject("PowerPoint.Application")
objApp.Activate

so the frame/window becomes available first

:O)Bruintje
0
 

Author Comment

by:jazzman2
ID: 7026979
Hi Bruintje,

The objApp.Activate solved the problem with Power Point ... Thank you.

I will test with my client this morning and let you know if everything works.

Thanks Again
Jazzman2
0
 

Author Comment

by:jazzman2
ID: 7028574
Hi Bruintje,

Sorry I didn't get back to you earlier but my client was not able to perform the tests today.

I will get back to you Thursday with the results.

Jazzman2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7028895
Hi Jazzman2,

It's OK got no time anyway

:O)Bruintje
0
 

Author Comment

by:jazzman2
ID: 7030713
Hi Bruintje,

The test went well with my client.

Thank you for all your help.

Please send me a comment and I will "Accept Comment As Answer" and close this question.

Thanks, once again.

Jazzman2
0
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 7031331
thanks Jazzman2, glad it worked out OK

i'll just recap it all here

Word
Dim objApp As Object
objApp.Documents.Open("c:\My Documents\myfile.doc")
'.....run the rest

Excel
Dim objApp As Object
objApp.Workbooks.Open("c:\My Documents\myfile.xls")
'.....run the rest

Powerpoint
Dim objApp As Object
Set objApp = CreateObject("PowerPoint.Application")
objApp.Activate
'.....run the rest

:O)Bruintje
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now