View Single Post
 
Old 02-01-2022, 05:32 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It is odd that Visio doesn't allow the usual vba file picker dialogs.

The first solution posted by PatricK in this thread works for my 32bit Visio and someone posted that it worked on a 64 bit version too.
vba - VBScript to open a dialog to select a filepath - Stack Overflow
Using that code I adapted it to test
Code:
Sub VisioFilePicker()
  Dim wShell As Object, sPath As String, oExec As Variant
  Set wShell = CreateObject("WScript.Shell")
  Set oExec = wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
  sPath = oExec.StdOut.ReadLine
  Debug.Print sPath
End Sub
It should be possible to find a solution which allows setting the default folder and filter to Excel files but it will likely take a lot more code.

I saw other solutions that make use of other Office applications to show the dialog. These allow filtering and setting default directories but would be slow to initiate. See open a fileDialog in visio vba - Stack Overflow as an example.

Yet other approaches use CommonDialogs but I think this is more likely to fail on 64bit machines. Add Open File Dialog to VBA
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote