Solved

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

Posted on 2002-05-21
23
256 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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