Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Office Server Quirks : Page 2

Automating the Office servers seems straightforward at first. But there are subtle (and not-so-subtle) differences in how they work that can trap unsuspecting developers.


advertisement
Can You See Me?
In general, Automation code executes faster when the server is not visible. With Word and Excel it's easy to take advantage of this situation because you can make the server visible and invisible at will.

In general, Automation code executes faster when the server is not visible.
PowerPoint, however, prefers to be visible. In fact, once you make the server visible you can't hide it again. That is, you can't set its Visible property to False—doing so causes an error. Fortunately, it instantiates with Visible set to False so you can gain performance by waiting until the presentation is built to display it.

More importantly, some properties aren't available unless PowerPoint is visible. The most significant item is the ActivePresentation property. When PowerPoint is hidden you can access presentations only through the Presentations collection, not directly via ActivePresentation.

There's another more general issue related to visibility: activating servers and documents. In some Automation situations you want to hand control over to the user and bring his attention to a particular document. While each of the object models has an Activate method, it doesn't apply to the same objects (or their analogues) in each application. In Word and PowerPoint, the Application object has an Activate method, so you can issue a call like:

oWord.Activate()

to give Word and its active document focus. Note that calling Activate doesn't necessarily bring Word or PowerPoint to the front, but it does make it flash in the taskbar. (Consider using the BringWindowToTop API function if that's not sufficient.)

Excel's Application object doesn't have an Activate method. However, setting the Visible property to True (even if it's already True) appears to have the same effect.

I Don't Want to See You
Office applications each maintain an MRU (most recently used) list, accessible from the File menu. This is very handy for interactive users who often want to return to the last document they were editing. However, when you're automating the applications you may not want the user to be able to easily return to documents created or edited by your application.

Preventing presentations from appearing on the MRU list in PowerPoint is easy because presentations opened via Automation aren't added to the list—so you don't have to do anything. In fact, it appears that there's no way to get an automated presentation onto PowerPoint's MRU list.

Word and Excel both let you control the MRU list. In Word, the Open method has a parameter, AddToRecentFiles, which determines whether the newly opened file appears on the list. Pass True to add the file to the list and False to prevent it from appearing. If omitted, the parameter is False, so newly opened files are not listed.

Word's SaveAs method also has an AddToRecentFiles parameter so that you can control this setting for newly created files and for files resaved with a new name. For this method, the parameter defaults to True. That is, once you save a file with SaveAs, it appears on the MRU list unless you prevent it.

By default, Excel doesn't add files opened or created via Automation to the MRU list, even when you save them. However, like Word, you can override the default behavior by passing a logical parameter to the Open or SaveAs method.

In addition to managing the MRU list when opening and closing files, both Word and Excel support a RecentFiles collection. You can explicitly add files to and remove files from the collection.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date