VBA HELP Command button

CodesiriuS

New Member
Joined
Dec 18, 2016
Messages
27
Hello - Im new to VBA and Im trying to make a userform that has a button that pretty much launches the window explorer but then lets the user navigate through the directory and upon selecting a file - also opens it so they can utilize other macros to format it. I have this so far but I don't know the code to open the file

Private Sub CommandButton1_Click()
ThisWorkbook.FollowHyperlink "file:\\c:"
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Just add the path and filename:

Private Sub CommandButton1_Click()
ThisWorkbook.FollowHyperlink "file:\\c:\path\file.txt"
End Sub

EDIT: Nevermind, I was a little to quick to post without really reading your question...
 
Last edited:
Upvote 0
Thanks BQardi!! This code upon button click will allow the users to search through the directory and open a file however, upon opening the selected workbook the selected file freezes up and wont let me close out of it. I'm trying to figure out if I should purse trying to troubleshoot this or just make the form to where the user clicks the button to get the file, and then once the file is selected the path shows up in an adjacent text box or something.Then the user can check what formatting options they want, then hit a processing button and be done with it. I have used other utilities like this but I'm green and still don't know what best practice is or in my case easier to start with. Any help or direction would be appreciated.
 
Upvote 0
You're welcome

As far as I understand, you are trying to change formatting of other workbooks, from this main workbook?

This is advanced in it self and probably harder when using userforms for this task (userforms lockup Excel until closed and this is probably the issue you are experiencing when trying to open another workbook).
I would recommend NOT using userforms for tasks like this when you are, as you said, "green"...
 
Upvote 0
If you want the user to chose a file then why not use Application.GetOpenFilename?
 
Upvote 0
It will get you the filename of the workbook the code has selected which you can then open using Workbooks.Open.
 
Upvote 0
This will allow the user to browse and open the file, but the name has to be extracted after its open

Code:
If Application.Dialogs(xlDialogOpen).Show Then
    MsgBox "The newly opened file is " & ActiveWorkbook.Name
Else
    MsgBox "User canceled"
End If
 
Upvote 0

Forum statistics

Threads
1,214,531
Messages
6,120,073
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top