Visio 2003 Developer's Survival Pack Tools and Samples

Chapter 32: Bitmap Export
Visio 2003 DSP home   This page

Overview

This example demonstrates how your code can control Visio's Save As process when saving a bitmap.

Visio's Automation model offers no control over the various bitmap parameters in the Save As process. A workaround is to try to control the process by using VB SendKeys to manipulate the dialogs and their controls. However, SendKeys works unreliably in this scenario, for reasons not entirely clear.

This sample shows a workaround for this workaround.

Files

File Description
SaveAsGraphic_MainSource.xls The main source for this sample is contained in an Excel VBA Project. This is in order to show that the method may be used from environments other than Visio itself, for example from Access or a VB6 project.
SaveAsGraphic.vsd Just a sample Visio document with an interesting page to practice saving as a bitmap.
   

Installation

This example also requires installing the DAKbdEventLib.dll component. Simply use regsvr32 on it, possibly using the SendTo approach described on this page: VBVSLNotes.htm > "Making regsvr32 More Convenient".

Running the Example

1. Open SaveAsGraphic_MainSource.xls. Open the VBA project. Open module  SaveAsGIF_Test.

2. Open Visio and open document SaveAsGraphic.vsd.

3. Back in the Excel VBA Project, run the procedure TestSaveAsGIF. Observe Visio's dialogs being rapidly manipulated. The result should be a file "test.gif", saved to the same directory as this sample.

Code Notes

The heart of the sample is the SaveAsGIF class module in the Excel VBA Project. The SaveAsGIF class exposes as properties all the settings that are available in Visio's Save As...GIF dialogs.

After the caller (for example procedure TestSaveAsGIF) sets these properties, it then calls SaveAsGIF.SaveAs. This is a lengthy routine but quite pedestrian. It simply grinds through each of the properties, and sends character sequences to Visio's dialogs to set the specified settings.

To save in some other format (such as BMP or TIF), you would create a class module similar to SaveAsGIF, replacing the GIF-dialog-specific code with code that corresponds to the BMP or TIF dialogs.

(Yes, this is one of those ever-popular "exercises for the reader"... sorry!).

Comment

Although this solution "works", it's obviously less than ideal. It's my great hope that in future versions, Visio will provide direct access to all these parameters via the Automation model.


Article Created: 2003-09-01  Last edit: Last edit: 03-10-15 Graham Wideman
Go to:
  DiagramAntics.com