Why oh why 16 Apr 2003
Gah! Rant time. Yesterday, I found myself in the position of having to detach some PowerPoint files from a document to a specific location on users’ hard drives, then have the code fire these documents up. Stage 1, the user’s home directory in Win2k / Win XP was easy. I dug out a wee API function (called GetUserName funnily enough) and Bob was my uncle in creating the path in which to detach the files. So far, so good. Stage (2): how best to launch the files? I tried Shell to no avail. I was trying to fire up PowerPoint, but also provide it with the path to the specific file. Now in Windows, you’d just use Run and type in something like:
powerpnt.exe c:\your path goes here\file.pps
No joy with Shell though. For one thing, it didn’t like an exe without an absolute path — fair enough — and for another I just could not pass in the file I wanted to open for love nor money. I was quoting and bracing here there and everywhere. Nope, couldn’t do it.
I was just considering querying the registry to get a definite location for the exe when, ding! I figured I’d use COM instead. Shell was never the ideal choice, as our users could have PowerPoint installed in different locations (especially with our mixed environment). However, COM doesn’t care about the physical location of the exe. “Splendid,” I thought, “all I have to do is something like this:”
Set appPP = CreateObject("PowerPoint.Application")
Oh no, not so simple. You can’t have a generic object like “PowerPoint”. It has to have version with it (“Application.Powerpoint.9” for Office 2000, “Application.Powerpoint.10” for Office XP I worked out). How pants is that? Instantiating an Excel application object (for example) doesn’t require this. So, my code works, but it has to test for the version of PowerPoint installed, thus:
' // Assume Office 2000 is the default
Dim appPP As Variant
Set appPP = CreateObject("PowerPoint.Application.9")
…
' // Raises an automation error in Office XP
If Err = 208 Then
Set appPP = CreateObject("PowerPoint.Application.10")
Resume Next
End If
Urgh. What a crappy implementation. Anyone else come up with nicer ways of doing stuff like this they could share? OK, so the solution presented here works fine in our environment, but… it offends my aesthetic sensibilities!
Further reading: Follow up to why oh why.
Not tested it on Office XP yet but it may prove useful.
regards
john marshalljohn marshall#
-ChrisChris Toohey#
Shellrequires that you kick off an exe or batch file. Then of course there's formula, but I had to use Lotusscript to cover the other bits of code.Ben Poole#Cheers,
JoeJoe Litton#
-thanksChris Harvey#
Chris: pants. The British "pants" refers to a gentleman's underwear rather than his trousers, as you probably know. When we say something is "pants" over here, it's a colloquialism for expressing our dissatisfaction with that something ;-)Ben Poole#
No?
Thought not… :-)Ben Poole#
OK, back into your problem Ben, I can't see the real problem by using Shell.
I had to do the same weeks ago to download an .html attached to a document, and what I did was, on the PostOpen even I detached the document to C:\, so I had a file like C:\myfile.html, then I needed to open the default browser, then I only did was invoking the file and the OS looks for the right app to launch the file. In case of html files, it uses the default browser and in case of *.pps or *.ppt files it will open , with no doubt, powerpoint no matter wich version you have. I hope it helps you..::AleX::.
Alex Hernandez#Dominocode.Net
- Julian Julian Robichaux#