UserForm and command button link

dboone25

Board Regular
Joined
May 8, 2015
Messages
185
Currently using Excel 2010 in where I have a command button called 'OpenFile' placed on a worksheet. This is linked to a Module.

This allows the user to select/open a .csv file which then opens in a new workbook. Once the file is loaded into the new workbook a UserForm also loads onto the active new sheet.

The code below shows this:


Code:
Option Explicit

Sub opencsv()




' Declare variables.
Dim myFile As String
Dim FileName As Variant
Dim myUserForm As FSelectFilter




' Select CSV file.
' Open dialog box title.
' Add title to open file dialogue box " Select .csv file to import


myFile = "CSV Files (*.csv),*.csv"
'Title = "Select .CSV File to Import"
FileName = Application.GetOpenFilename(Title:="Select .csv File to Import")
                                                                          
' Select and open the dialog box.
' If no file selected open dialog box.
If FileName = False Then
MsgBox "No File Selected"
Exit Sub
End If




'Show userform on current sheet
Set myUserForm = New FSelectFilter
     myUserForm.Show




'Change active sheet name
ActiveSheet.Name = "Sheet1"




End Sub


What im trying to get working is add another command button underneath onto the same worksheet where the 'LoadFile' command button so if the user closes the UserForm this can be called from the original work book but only to open the UserForm.

Can this be done?

I assumed its something simple as:

Code:
Private Sub CommandButton1_Click()

    myUserForm.Show




End Sub


Any help is much appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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