Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-31-2022, 10:26 PM
Jamesp435 Jamesp435 is offline Visio VBA - Find file button... Windows 10 Visio VBA - Find file button... Office 2021
Novice
Visio VBA - Find file button...
 
Join Date: Jan 2022
Posts: 2
Jamesp435 is on a distinguished road
Default Visio VBA - Find file button...

Hi team



I'm using VBA in Visio 64 bit Plan 2 (I'm assuming this is the O365 version).

I want a button that when I click allows me to select a (ideally Excel only) file similar to if I'm using file explorer (this would then show the directory and file name of the selected file in a text box, and this will allow me to then open the file with other vba code). But I'm struggling to find out how this is down.

Any help gratefully received

Many thanks

James
Reply With Quote
  #2  
Old 02-01-2022, 05:32 PM
Guessed's Avatar
Guessed Guessed is offline Visio VBA - Find file button... Windows 10 Visio VBA - Find file button... Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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
  #3  
Old 02-01-2022, 08:02 PM
Jamesp435 Jamesp435 is offline Visio VBA - Find file button... Windows 10 Visio VBA - Find file button... Office 2021
Novice
Visio VBA - Find file button...
 
Join Date: Jan 2022
Posts: 2
Jamesp435 is on a distinguished road
Default Thank you...

Nice one Andrew. Thanks for your time posting this.

James
Reply With Quote
Reply

Tags
visio vba macros

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visio crashed & now file is blank Moorhs Visio 1 12-27-2021 08:49 AM
Find the appropriate visio diagram nightearth Visio 1 08-02-2021 04:10 PM
Link image from file into Visio Vind Visio 0 11-08-2018 12:11 AM
Rename visio file & hyperlink O'Neill Visio 0 05-08-2016 11:43 PM
Visio VBA - Find file button... How do you find what command a toolbar button represents? New Daddy Word 6 05-05-2012 12:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:14 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft