Sample VBA macro to send a drawing to a specific printer in Visio (300134)



The information in this article applies to:

  • Microsoft Office Visio Professional 2003
  • Microsoft Office Visio Standard 2003
  • Microsoft Visio 2002 Professional
  • Microsoft Visio 2002 Standard

This article was previously published under Q300134

SUMMARY

This article contains a sample Microsoft Visual Basic for Applications macro to specify a printer or a plotter, and to send the drawing to that device.

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.

Sample macro

The following sample Visual Basic macro for specifying a printer uses the PageSheet property of the Page object to switch the page width and height values.
Public Sub PrintThisDoc()
    'Set up a dummy print object
    Dim docObj As Visio.Document
    Dim docObjTemp As Object
    Dim dummy As String
    
    Set docObj = ThisDocument
    Set docObjTemp = docObj
    ' The printer name must be spelled exactly 
    ' as you find it in the printers list in the 
    ' File/Print dialog box. 
    ActiveDocument.Printer = "MS Printer 350"
    'Send the document to the specified device
    dummy = docObjTemp.Print
End Sub
				

REFERENCES

For more information about how to use the sample code in this article, click the following article number to view the article in the Microsoft Knowledge Base:

277011 How to run sample code from Knowledge Base articles

For the latest information, hot topics, resources, downloads, and more for the Visio developer, browse to the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/12/2006
Keywords:kbhowto kbinfo KB300134