Visio2000: Sample Macro to Get the Current Drawing Name and Full Path (272742)



The information in this article 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.
  4. 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.
  5. 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, "Drawing Name:"
   
   ' Display the filename and full path in a message box.
   MsgBox strDocFullPath, vbInformation + vbOKOnly, "Drawing Name and Path:"
   
   ' Set the text box properties accordingly.
   UserForm1.TextBox1.Text = strDocName
   UserForm1.TextBox2.Text = strDocFullPath
   
   ' Set the label text properties.
   UserForm1.Label1.Caption = "Document name:"
   UserForm1.Label2.Caption = "Document path:"

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

REFERENCES

For additional information about using the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

277011 Visio2000: How to Run Sample Code from Knowledge Base Articles


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