The script provides data transfer to a Visio document more convenient and faster than the file selection dialog box.

The script is designed to work with Visio TreeView template.

Visio provides a dialog for selecting files, but is limited by an unregulated filter. Only Visio files can be selected, but not arbitrary files. Therefore, the developer himself has to create a dialog box for selecting a data file. But this requires a lot of code.

The developer can use the InputBox to provide the user with the ability to manually enter the path to the data file or copy it from the Windows Explorer window. This is more convenient, but not enough.

The next step is to try to “transfer” the data file from the explorer to the document. This method is used in the Visio TreeView template.

There is a script "TreeView starter" written in VBS. The script icon is located on the desktop. When "throwing" a data file onto the script icon, the script does the following:

  • Selects a file path from command line arguments.
  • Creates a Visio document using the Visio TreeView template.
  • Writes the file path to the DocumentSheet.Data3 field

The Visio document now contains information about the location of the data file. You just need to take them from the corresponding field and enter them in the InputBox.

If now the user performs the “Import from File” operation, the InputBox field will contain the file path substituted from DocumentSheet.Data3. The user only needs to press the OK key.

Instructions for use

Copy the script text and save it in a file with the extension .vbs.
Make a Shortcut for the script file and place it on the Windows desktop.

Script text

 

' 1 ===== Drag&Dropping new data file
If WScript.Arguments.Count > 0 Then
  ' The file was Drag&Dropped to VBS script
  docName = WScript.Arguments(0)
  'docPath = Mid(docName,1,InStrRev(docName,"\"))
  'MsgBox docName
Else 
  WScript.Quit
End If

' 2 ===== Create Visio document
Dim vApp
Dim vDoc
Set vApp = Nothing
On Error Resume Next
Set vApp = CreateObject("Visio.Application")
Set vDoc = vApp.Documents.Add("D_2019e.vst")
If vApp is Nothing or vDoc is Nothing Then
  MsgBox "Visio document must be opened."
  WScript.Quit
End If
On Error Goto 0

'Check 'folder' master
On Error Resume Next
Set mf = Nothing
Set mf = vDoc.Masters("folder")
If mf is Nothing Then
  MsgBox "Visio document must be created on TreeView template."
  WScript.Quit
End If
On Error Goto 0
vDoc.DocumentSheet.Data3 = docName

Add comment


Security code
Refresh