Run time error '1004' Workbook.Open

abi_learn_vba

Board Regular
Joined
Nov 6, 2009
Messages
215
Hi,

I have used a Userform to browse a file, and the file path in the textbox is saved to the variable "input", please see the code below. Then i called and procedure "ProcessInput" (Which is in Module) to open the file. But when the module is opened the Input value shows "empty" and it does not have the path name. But as i see the filename is saved in the variable "input" in "Private Sub cmdOK_Click() ". Can any one say if i am wrong in doing this?

Code:
Private Sub cmdOK_Click()
If Trim(TextBox1.Text) = "" then
    MsgBox "One or All Files are not Selected!! Try Again"
        Exit Sub
    End If
    Input = TextBox1.Text
    Call ProcesInput
    Unload Me
End Sub
 
Public Sub ProcesInput()
Set myfile = Workbooks.Open(Input)
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try

Code:
Dim MyInput As String, myfile As Workbook
Private Sub cmdOK_Click()
If Trim(TextBox1.Text) = "" Then
    MsgBox "One or All Files are not Selected!! Try Again"
        Exit Sub
    End If
    MyInput = TextBox1.Text
    Call ProcesInput
    Unload Me
End Sub
 
Public Sub ProcesInput()
Set myfile = Workbooks.Open(MyInput)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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