• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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

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
jazzman2
Asked:
jazzman2
  • 11
  • 10
  • 2
1 Solution
 
bruintjeCommented:
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
 
jazzman2Author Commented:
Hi bruintje,

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

jazzman2
0
 
BangerterCommented:
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
jazzman2Author Commented:
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
 
bruintjeCommented:
Hi Jazzman2,

you say this is after upgrading, but is this now on a machine with two installations?
0
 
jazzman2Author Commented:
Hi bruintje,

Yes, the PC has both Office 97 and Office 2000

Jazzman2

0
 
bruintjeCommented:
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
 
jazzman2Author Commented:
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
 
bruintjeCommented:
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
 
bruintjeCommented:
where App is Excel, Word etc...
0
 
jazzman2Author Commented:
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
 
BangerterCommented:
for mine you will need to set the reference to the excel object library.
0
 
bruintjeCommented:
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
 
jazzman2Author Commented:
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
 
bruintjeCommented:
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
 
jazzman2Author Commented:
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
 
jazzman2Author Commented:
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
 
bruintjeCommented:
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
 
jazzman2Author Commented:
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
 
jazzman2Author Commented:
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
 
bruintjeCommented:
Hi Jazzman2,

It's OK got no time anyway

:O)Bruintje
0
 
jazzman2Author Commented:
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
 
bruintjeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 11
  • 10
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now