Export function from VBA does not produce the same output layout as using SaveAs

K

K. Chen

hi, all, I'm trying to automate the process to export some Visio
diagrams HTML format. The VBA program works ok, but the output is
somewhat different to the result produced when you do SaveAs HTML in
Visio. When using VBA, it produced a pulldown menu at the bottom right
with a list of display sized, default being "Fit on Screen", this is
normally too small to see comfortably and needs resizing, which is
painful when you have to do it for every page.

When I do a SaveAs HTML, the output produced is the exact size as you
see in Visio, which is much more pleasant. Anybody has any idea on how
to produce this output? Following is the VBA function that produced
the output. I tried this in Visio 2000 SR1.

TIA
KC

Sub SaveAsHTML(pages As Visio.pages, htmlFolder As String, baseName As
String)

' error handler
On Error GoTo ErrorHandle

' get proper basename
baseName = Left(baseName, Len(baseName) - 4)

' 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("JPG")
'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
expData.Document = htmlFolder & ".vsd"


' 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.
expData.BaseFileName = baseName & ".htm"

' Add a page.
'expData.pages.Add ActivePage.Name
Dim i As Integer
For i = 1 To pages.Count
expData.pages.Add pages(i)
Next i

' Initialize export manager.
Dim mgr As New ExportMgrDrawing
' Set the output folder.
mgr.OutputFolder = htmlFolder
' Set the export data.
Set mgr.ExportData = expData

' Perform the export.
mgr.Export Visio.Application
Exit Sub
ErrorHandle:
MsgBox "You raised error: " & _
Err & ", " & Err.Description & _
vbCrLf & _
"At program location: " & _
Err.Source
End Sub
 
A

Andy [MS]

How are you doing your "SaveAs HTML"? I'm confused by the difference in how
you're creating the pages. Thanks.
 
K

K. Chen

Hi, Andy, I call the SaveAs function as following:

Call SaveAsHTML(pagsObj, SubDirName, CurrFileName)

the SubDirName and CurrFileName are just things that I use to parse to
create subdirectories where the HTMLs will reside.

The HTML produced using the code has a zoom size pull down list at the
bottom right (in addition to the page navigation pull down list at the
bottom middle) and it's defaulted to "Fit on Page". what I was really
looking for is a way to manipulate this behavior..

I did found the Visio2002's SaveAsWeb API and are going to try that,
it should give me more options of controlling the look and feel of the
output.

will post the results here once it's done.
thanks.
KC
 
K

K. Chen

ok, I'm running into difficulties. Using Visio2002 with SP1 and Visual
Studio 6. when trying to generate HTML, code keeps crashing with the
following error message:
Run-time error '-2147467259(80004005)':
Method 'CreatePages' of object 'IVisSaveAsWeb' failed.

My code is as follows:

Private Sub Command1_Click()
'Dim saveAsWeb As IVisSaveAsWeb
'Dim webSettings As IVisWebPageSettings
Dim webSettings As VisWebPageSettings
Dim saveAsWeb As VisSaveAsWeb

Dim visioApp As Visio.Application
Set visioApp = New Visio.Application

Dim docAdded As Visio.Document
Set docAdded = visioApp.Documents.Open("c:\test\test.vsd")


Set saveAsWeb = New VisSaveAsWeb

Set webSettings = saveAsWeb.WebPageSettings

Call saveAsWeb.AttachToVisioDoc(docAdded)


' Configure our preferences.
webSettings.StartPage = 1
webSettings.EndPage = 2
webSettings.LongFileNames = True
webSettings.QuietMode = True
webSettings.PageTitle = "hello world"

webSettings.TargetPath = "c:\test\test.htm"

Call saveAsWeb.CreatePages

docAdded.Close
visioApp.Quit

End Sub


Visio is opened and file's loaded ok, but when the CreatePages is
called, crash occurs.

According to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devref/HTML/SAW_Objects_30.asp,
this should work..
Anybody can help?

thanks
KC.
 
A

Andy [MS]

Is this VB6?

Visio's Save as Web object (VisSaveAsWeb) can only be created this way if
this is VBA inside Visio or a Visio VSL. Basically, the object can't be
created outside of Visio's process. This is documented on one of the web
pages you referenced:

"The Save as Web Page object model cannot be used from an executable that is
running in its own process (outside of the Visio address space). To control
Save as Web Page from an executable, you must use the command-line
interface."

To work around this, you can use the command line interface for SAW. Look
for the topic titled "Running Save as Web Page from the command line".

BTW, this has been improved in Visio 2003. In 2003, you can get the
VisSaveAsWeb object directly from Visio's Application object, which lets you
use it in a process outside of Visio.

Hope this helps.
 
K

K. Chen

I installed Visio2003, enterprise architect edition, and VS.NET. Using
VB.NET, I tested the following code:

Imports Microsoft_Visio_SaveAsWeb
Module Module1

Sub Main()
Dim saveAsWeb As Microsoft_Visio_SaveAsWeb.IVisSaveAsWeb
Dim webSettings As
Microsoft_Visio_SaveAsWeb.IVisWebPageSettings

Dim visioApp As Visio.Application
visioApp = New Visio.Application

Dim docAdded As Visio.Document
docAdded = visioApp.Documents.Open("c:\test.vsd")

saveAsWeb = New Microsoft_Visio_SaveAsWeb.VisSaveAsWeb

' Get a VisWebPageSettings object.
webSettings = saveAsWeb.WebPageSettings

' Configure our preferences.
webSettings.LongFileNames = True

webSettings.TargetPath = "c:\test.htm"

saveAsWeb.AttachToVisioDoc(docAdded)

saveAsWeb.CreatePages()
docAdded.Close()

End Sub

End Module

At CreatePages, it failed with the following message,
"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occured in MyApp.exe"
I read up a bit on this exception and understood that these
InteropServices assemblies are needed when developing Office solutions
that's bridging the .NET framework with COM. As this is not the case,
I'm really confused as to what I need here. Just for fun, I tried this
in place of saveAsWeb.CreatePages(),

visioApp.Addons("SaveAsWeb").Run("/quiet=true /target=c:\test.htm")

this seem to have worked(generated the HTML file) but then the program
can not close the SaveAsWeb window. Not sure what this proofs but I'm
sure I'm missing something here.

thanks
K.C
 
A

Andy [MS]

Did you mean Visio 2002? There is no Visio 2003 Enterprise Architect Edition
at this point.

The results you are seeing are expected. You cannot create the SAW object
outside of the Visio address space. If you tell the app to run the SaveAsWeb
addon, it will work fine.

I'm not sure what you mean when you say it can't close the "SaveAsWeb
window". Passing in a "true" value for the "quiet" parameter should prevent
the Save as Web "Save As" type of window from popping up.

--
Andy
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.


K. Chen said:
I installed Visio2003, enterprise architect edition, and VS.NET. Using
VB.NET, I tested the following code:

Imports Microsoft_Visio_SaveAsWeb
Module Module1

Sub Main()
Dim saveAsWeb As Microsoft_Visio_SaveAsWeb.IVisSaveAsWeb
Dim webSettings As
Microsoft_Visio_SaveAsWeb.IVisWebPageSettings

Dim visioApp As Visio.Application
visioApp = New Visio.Application

Dim docAdded As Visio.Document
docAdded = visioApp.Documents.Open("c:\test.vsd")

saveAsWeb = New Microsoft_Visio_SaveAsWeb.VisSaveAsWeb

' Get a VisWebPageSettings object.
webSettings = saveAsWeb.WebPageSettings

' Configure our preferences.
webSettings.LongFileNames = True

webSettings.TargetPath = "c:\test.htm"

saveAsWeb.AttachToVisioDoc(docAdded)

saveAsWeb.CreatePages()
docAdded.Close()

End Sub

End Module

At CreatePages, it failed with the following message,
"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occured in MyApp.exe"
I read up a bit on this exception and understood that these
InteropServices assemblies are needed when developing Office solutions
that's bridging the .NET framework with COM. As this is not the case,
I'm really confused as to what I need here. Just for fun, I tried this
in place of saveAsWeb.CreatePages(),

visioApp.Addons("SaveAsWeb").Run("/quiet=true /target=c:\test.htm")

this seem to have worked(generated the HTML file) but then the program
can not close the SaveAsWeb window. Not sure what this proofs but I'm
sure I'm missing something here.

thanks
K.C


"Andy [MS]" <[email protected]> wrote in message
Is this VB6?

Visio's Save as Web object (VisSaveAsWeb) can only be created this way if
this is VBA inside Visio or a Visio VSL. Basically, the object can't be
created outside of Visio's process. This is documented on one of the web
pages you referenced:

"The Save as Web Page object model cannot be used from an executable that is
running in its own process (outside of the Visio address space). To control
Save as Web Page from an executable, you must use the command-line
interface."

To work around this, you can use the command line interface for SAW. Look
for the topic titled "Running Save as Web Page from the command line".

BTW, this has been improved in Visio 2003. In 2003, you can get the
VisSaveAsWeb object directly from Visio's Application object, which lets you
use it in a process outside of Visio.

Hope this helps.

--
Andy
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Top