set file path as a workbook error

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hi i am trying to get a user to select a file and set tht file path as a string then with that string set that as a workbook since i am trying to reference an outside workbook and worksheet but getting an error here

Set Wbl = wokrbooks.EUR_FName

Object required run time error 424

VBA Code:
Sub get_data()

Dim OpenFileName As String, srcWS As Worksheet
EUR_FName = Application.GetOpenFilename("Excel files (*.xls*), *.xls*")

Dim Wb1 As Workbook
Set Wbl = wokrbooks.EUR_FName
Set srcWS = Wbl.Sheets("Sheet1")

not sure what i need to do to fix this
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try it like this...

VBA Code:
Sub get_data()

    Dim OpenFileName As Variant
    OpenFileName = Application.GetOpenFilename( _
        FileFilter:="Excel files (*.xls*), *.xls*", _
        Title:="Select Excel file", _
        ButtonText:="Select")
        
    If OpenFileName = False Then Exit Sub
        
    Dim Wb1 As Workbook
    Set Wb1 = Workbooks.Open(OpenFileName)
    
    Dim srcWS As Worksheet
    Set srcWS = Wb1.Sheets("Sheet1")
    
End Sub

Hope this helps!
 
Upvote 0
Try it like this...

VBA Code:
Sub get_data()

    Dim OpenFileName As Variant
    OpenFileName = Application.GetOpenFilename( _
        FileFilter:="Excel files (*.xls*), *.xls*", _
        Title:="Select Excel file", _
        ButtonText:="Select")
       
    If OpenFileName = False Then Exit Sub
       
    Dim Wb1 As Workbook
    Set Wb1 = Workbooks.Open(OpenFileName)
   
    Dim srcWS As Worksheet
    Set srcWS = Wb1.Sheets("Sheet1")
   
End Sub

Hope this helps!
Yes this helps a lot, if you dont mind, i am trying to get the last row used from cell a3 down but getting an error on the line

LR = srcWS.range("A3" & rows.Count).End(xlUp).Row

VBA Code:
Sub get_dataa()

    Dim OpenFileName As Variant
    Dim LR As Long
    OpenFileName = Application.GetOpenFilename( _
        FileFilter:="Excel files (*.xls*), *.xls*", _
        Title:="Select Excel file", _
        ButtonText:="Select")
        
    If OpenFileName = False Then Exit Sub
        
    Dim Wb1 As Workbook
    Set Wb1 = Workbooks.Open(OpenFileName)
    
    Dim srcWS As Worksheet
    Set srcWS = Wb1.Sheets("Sheet1")
    
    LR = srcWS.range("A3" & rows.Count).End(xlUp).Row
 
Upvote 0
You need to remove the "3" after "A3", i.e.
VBA Code:
LR = srcWS.range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0
i
Yes this helps a lot, if you dont mind, i am trying to get the last row used from cell a3 down but getting an error on the line

LR = srcWS.range("A3" & rows.Count).End(xlUp).Row

VBA Code:
Sub get_dataa()

    Dim OpenFileName As Variant
    Dim LR As Long
    OpenFileName = Application.GetOpenFilename( _
        FileFilter:="Excel files (*.xls*), *.xls*", _
        Title:="Select Excel file", _
        ButtonText:="Select")
      
    If OpenFileName = False Then Exit Sub
      
    Dim Wb1 As Workbook
    Set Wb1 = Workbooks.Open(OpenFileName)
  
    Dim srcWS As Worksheet
    Set srcWS = Wb1.Sheets("Sheet1")
  
    LR = srcWS.range("A3" & rows.Count).End(xlUp).Row
Try it like this...

VBA Code:
Sub get_data()

    Dim OpenFileName As Variant
    OpenFileName = Application.GetOpenFilename( _
        FileFilter:="Excel files (*.xls*), *.xls*", _
        Title:="Select Excel file", _
        ButtonText:="Select")
       
    If OpenFileName = False Then Exit Sub
       
    Dim Wb1 As Workbook
    Set Wb1 = Workbooks.Open(OpenFileName)
   
    Dim srcWS As Worksheet
    Set srcWS = Wb1.Sheets("Sheet1")
   
End Sub

Hope this helps!
i noticed that the file does open, is there a way to close the file at the end? also to check if that file has filtered columns and to clear those filters?
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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