Compile error help and centering Title on userform

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The below code gives me a compiling error. "Compile error: Wrong number of arguments or invalid property assignment" The error seems to occur on the .Filters.Add
The .Add is highlighted in blue if that helps.

How can I center the title text on a userform.

Code:
Private Sub cmdBrowse_Click()    
    'myFile = Application.GetOpenFilename(, , "Select a File.")
    
    Dim fname As String
    Dim fpath As String
    
    fpath = ThisWorkbook.Path
    
    With Application.FileDialog(msoFileDialogOpen)
        .InitialFileName = fpath
        .ButtonName = "Get File Name"
        .Title = "File Selection"
        .Filters.Clear
        .Filters.Add "*.xl", "*.xlsx", "*.xlsm", "*.xlb", "*.xlam", "*.xltx", "*.xltm", "*.xls", "*.xla", "*.xlt", "*.xlm", "*.xlw"
        .AllowMultiSelect = False
        
        If .Show = True Then
            fname = .SelectedItems(1)
            Me.TextBox1.Text = fname
        Else
            MsgBox "Operation Canceled"
        End If
    End With
End Sub
Thank You
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The number of arguments was wrong. Pressing F1 while the cursor is on the word Filters takes you to a help page with an example of Filters.Add.

Code:
.Filters.Add "Excel files", "*.xl;*.xlsx;*.xlsm;*.xlb;*.xlam;*.xltx;*.xltm;*.xls;*.xla;*.xlt;*.xlm;*.xlw"

I don't know how you can format the title to be centered on a built-in dialog box. Probably can't be done. Though a work around would be to add a bunch of spaces in front of the text to move it to the right.
 
Last edited:
Upvote 0
Thank you. That worked. I see where I went wrong. I forgot to ask, but to open the file, I would have to create an open button and put
Code:
fname.open
to open the file. Is that correct? Thank you for your help.
 
Upvote 0
The code to open the workbook is

Code:
Workbooks.Open fname
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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