Visio2000: Sample Macro to Automate Save As HTML (258489)



The information in this article applies to:

  • Microsoft Visio 2000 Standard Edition
  • Microsoft Visio 2000 Technical Edition
  • Microsoft Visio 2000 Professional Edition
  • Microsoft Visio 2000 Enterprise Edition

This article was previously published under Q258489

SUMMARY

This article demonstrates how to use the Visio HTML Export Support Objects found in Vishtmlo.dll to automate exporting a Visio drawing as an HTML document set.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The Visual Basic for Applications sample code demonstrates how to automate the process of exporting a Visio drawing as an HTML document set. This example does not automate the Save As HTML Wizard; rather, it calls the Vishtmlo.dll file directly.

This code block creates an HTML document set with the base name Test.htm in C:\My Documents folder.

NOTE: In order for this object to work, you must reference the Visio HTML Export Support Objects library. To load the library into the current VBA project follow these steps:
  1. Press ALT+F11 to open Visual Basic Editor.
  2. On the Tools menu, click References.
  3. Click to select the Visio HTML Export Support Objects check box under Available References, and then click OK.
Type or paste the following code.
Option Explicit

' SaveAsHTML
'
' Demonstrates the use of the undocumented VisioHTML objects.
' The VisioHTML objects drive the "Save As HTML" feature of Visio.
' The *documented* method of saving HTML is the Export method of Page or
' Selection.
' However, Export does not allow the programmer to set any of the options
' available in the UI.
'
' "Visio HTML Export Support Objects" must be available in
' Tools References.
'

' MapType constants
Const visMapTypeClient = 1
Const visMapTypeNCSA = 2
Const visMapTypeCERN = 4

Sub SaveAsHTML()

   ' Initialize the filters collection.
   Dim flts As New Filters
   Set flts.Parent = Visio.Application
        
   ' Get the Vector filter.
   ' VML, GIF, JPG, and PNG are valid options.
   Dim fltVector As Filter
   Set fltVector = flts.Item("VML")

   ' Get the Raster filter.  Needed if the vector filter is VML.
   ' JPG and PNG are valid options.
   Dim flt As Filter
   Set flt = flts.Item("GIF")

   ' initialize Utilities
   Dim utils As New Utilities
    
   ' Initialize themes.
   Dim thm As theme
   Dim thms As themes
   Set thms = utils.LoadThemes()

   ' Only one theme is available, "Default"
   Set thm = thms.Item(1)
    
   ' Initialize export data.
   Dim expData As New ExportData
    
   ' Set the VSD.
   expData.Document = Me.Name
   ' Set the vector filter.
   Set expData.VMLFilter = fltVector
   ' Set the raster filter.
   Set expData.Filter = flt
   ' Expose hyperlinks?
   expData.ExposeHyperlinks = True
   ' set the map type, see constants above.
   expData.MapType = visMapTypeClient
   ' if MapType is CGI...
   expData.CGIMap = ""
   ' Set the theme.
   Set expData.theme = thm
   ' Set the output file name.
   ' Supporting files will derive their names from the base name.
   expData.BaseFileName = "Test.htm"
    
   ' Add a page.
   expData.Pages.Add ActivePage.Name
    
   ' Initialize export manager.
   Dim mgr As New ExportMgrDrawing
   ' Set the output folder.
   mgr.OutputFolder = "C:\My Documents"
   ' Set the export data.
   Set mgr.ExportData = expData
        
   ' Perform the export.
   mgr.Export Visio.Application

End Sub
				

The only method in the Visio engine to automate Save As HTML is the Export method of Page or Selection. For example:

   ActivePage.Export "c:\test.htm"
				
This method uses the same options that were last used by the Save As HTML Wizard. You cannot set these settings programmatically.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto KB258489