You know, sometimes it's the obvious things you miss. I was meeting a few days ago with the programmer-writer who is taking over writing Publisher developer help for the next release. I was giving him a guided tour of the Publisher object model, and I thought "you know, this should really be written down somewhere."
I had written an entire series for beginning developers on how to get started with the Publisher object model. But somehow I had never gotten around to writing an article that contained the things an experienced programmer would want to know if they were coming to the Publisher object model—and perhaps Publisher as a whole—for the first time.
So I've decided to see if I can't write a series of entries here that address the issues an experienced programmer would encounter as they ramp up on the Publisher object model. With any luck, I'll be able to roll them into an actual article somewhere down the road.
Here's the first of those topics. It's a snappy little number I like to call:
Creating Web Pages with the Publisher Object Model
You can create web pages with Publisher 2003. In Publisher 2003, there are two types of publications: print publications, and web publications. A web publication represents a group of web pages. Each publication page corresponds to a single web page. You create and design the pages within Publisher as you would a print publication. When you have finished designing your web publication, you publish the file to the web.
You can also publish a print publication to the web; however, the appearance of the Web pages may differ from the printed publication.
When Publisher publishes a publication to the web, it creates an HTML representation of each page in the publication, and then saves those HTML files, along with any necessary supporting files, to the specified URL location.
The HTML files that Publisher publishes have no link to the original Publisher file used to generate them. If you later need to make changes to the web pages, do not edit them directly. Rather, make your changes to the original Publisher web publication, and then re-publish the file to the same URL location. Changes made to the HTML directly are not propagated back to the original web publication; indeed, if you do edit the HTML, and later re-publish the Publisher file, your changes are overwritten.
By default, Publisher treats the first page in the publication as the initial page in your web site. By default, Publisher saves the HTML file representing the first publication page as 'index.htm'. Publisher saves the HTML pages for any other publication pages, as well as any support files (such as image files), in a folder called 'index_file', located in the same directory as the index file. If you do not specify the file name for an HTML file, Publisher generates a name for it automatically.
To determine if a publication is a print or web publication, use the Document.PublicationType property. To convert a print publication to a web publication, or vice versa, use the Document.ConvertPublicationType method. Note that this overwrites the previous version of the file.
To publish a file to the web, use the Document.SaveAs method. For the Format parameter, specify pbFileHTMLFiltered. For the FileName parameter, specify the URL location to which you want to publish the file. This corresponds to choosing the Publish to the Web command from the File menu. Note that the .htm file extension is automatically added to the value of the Filename parameter if the value of the Format parameter is pbFileHTMLFiltered.
This example saves the active Web publication as a set of filtered HTML pages and supporting files. In this example, Publisher names the HTML file representing the first publication page after the original web publication name. (Note that URLPath must be replaced with a valid file path for this example to work.)
.SaveAs Filename:="URLPath" & .Name, Format:=pbFileHTMLFiltered
Note The pbFilePublicationHTML value of the Format parameter represent an HTML file format available in Publisher 2002 that enabled re-importation of the HTML Publisher generated. Because of the resulting large file size, however, this file format has been deprecated and should not be used.
If you specify pbFileWebArchive for the Format parameter, Publisher generates an .mht file. An .mht file is an HTML file that has all of its support files, such as images and other files, embedded in it.
If you later make changes to the web publication and need to re-publish it, simply use the SaveAs method with the same file path specified. This overwrites the existing HTML files; no warning is given.
To generate a preview of a web publication, use the Document.WebPreview method. This method generates a local HTML copy of the publication, and displays it in the users default browser. The Web preview opens with the active page displayed. Preview Web pages are generated for each page in the publication. However, if the publication is a print publication or otherwise lacks a navigation bar, there may be no way to navigate to those pages.
The following example sets the active page of the publication and generates a Web preview of the publication.
.ActiveView.ActivePage = .Pages(2)
Publisher 2003 includes pre-defined web navigation bars that you can include in your Web publication. For more information on how to use web navigation bars programmatically, see Adding Navigation Bars to Web Publications in Microsoft Office Publisher 2003.
To specify settings for the web publications you create, use the WebOptions object. This object contains properties that represent settings that newly created Web publication inherit, such as encoding and font options. When you modify any of these settings, any Web publications you create inherit the modified properties.
For example, if you need to re-publish a large Web publication, you might want to set the EnableIncrementalUpload to True. This specifies that only changes made to a publication will be uploaded to the Web server when published, rather than the entire publication. The EnableIncrementalUpload property applies only to Web publications that have already been published to a Web server. If a Web publication has not already been published to a Web server, the entire publication will be published to the server during the initial publishing process, regardless of whether the EnableIncrementalUpload property is set to True.
The WebOptions object settings are application-level settings specific to each user.
To specify web properties for a specific page, use the WebPageOptions object. This object contains properties that represent web characteristics of the specified publication page, such as background sound, page description, and whether to include the page on new web navigation bars. To specify a file name for the HTML file generated from a publication page, use the WebPageOptions.PublishFileName property. As mentioned earlier, specifying a file name for a Web page is optional. When a publication is saved as filtered HTML, Publisher automatically generates file names for any Web page that does not have a file name specified. User defined file names are only used when a publication is saved as filtered HTML. File names must be specified without a file extension.