Microsoft KB Archive/272742

= Visio2000: Sample Macro to Get the Current Drawing Name and Full Path =

Article ID: 272742

Article Last Modified on 1/29/2007

-

APPLIES TO


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

-



This article was previously published under Q272742



SUMMARY
This article provides a sample Microsoft Visual Basic for Applications macro (Sub procedure) that displays the current drawing name and path in message boxes and a UserForm.



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.

In the following example, the UserForm contains two label and two text box controls for displaying the drawing name and the file name with a full path.

Creating the UserForm
To create the UserForm, follow these steps:
 * 1) In your current Visio project, press ALT+F11 to start the Visual Basic Editor.
 * 2) On the Insert menu, click UserForm.
 * 3) Click the Label control on the Toolbox toolbar, and then click the UserForm. Repeat this step to add a second label control.

The label control appears in the default size. Click the label control on the UserForm, and drag a sizing handle to resize the control, or drag the control to move it to a new location.
 * 1) Click the TextBox control on the Toolbox toolbar, and then click the UserForm. Repeat this step to add a second text box control.

The text box control appears in the default size. Click the text box control on the UserForm, and drag a sizing handle to resize the control, or drag the control to move it to a new location.

NOTE: Make the TextBox2 control wide enough to accommodate a long file path.
 * 1) On the Insert menu, click Module, and then type or paste the following procedure:

Sub GetDocName ' Declare (dimension) variables. Dim docObj As Visio.Document Dim strDocName As String Dim strDocFullPath As String

' Get the first document in the Documents collection. Set docObj = Documents.Item(1)

' Get the current document object's Name and FullName properties. strDocName = docObj.Name strDocFullPath = docObj.FullName ' Display the filename in a message box. MsgBox strDocName, vbInformation + vbOKOnly, &quot;Drawing Name:&quot; ' Display the filename and full path in a message box. MsgBox strDocFullPath, vbInformation + vbOKOnly, &quot;Drawing Name and Path:&quot; ' Set the text box properties accordingly. UserForm1.TextBox1.Text = strDocName UserForm1.TextBox2.Text = strDocFullPath ' Set the label text properties. UserForm1.Label1.Caption = &quot;Document name:&quot; UserForm1.Label2.Caption = &quot;Document path:&quot;

' Show the UserForm populated. UserForm1.Show vbModeless ' UserForm is Modeless End Sub

