naming workbook to be recognised in vba

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Guys,

This must be a simple one but I cannot see what I am missing. My code is below, it open a prompt to choose a workbook that I extract data from. I need this workbook to be referenced later in my code. I am trying to reference it as wb1 but it does not work, can anyone see the issue please?

' Open Downloaded Data
Dim wb1 As Workbook
Dim fileNameAndPath As Variant
fileNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.csv), *.csv", Title:="Select your Downloaded File")
If fileNameAndPath = False Then Exit Sub
Workbooks.Open Filename:=fileNameAndPath
Set wb1 = ActiveWorkbook

Thanks


Fletch
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It does look OK to me. But try to set it as you open it maybe.

VBA Code:
Set wb1 =  Workbooks.Open Filename:=fileNameAndPath
 
Upvote 0
It does look OK to me. But try to set it as you open it maybe.

VBA Code:
Set wb1 =  Workbooks.Open Filename:=fileNameAndPath
My problem is I need to reference it as it may now be the same name every time. But every time I run it wb1 appears blank and just doesn't get the sheet name?
 
Upvote 0
Try this.
VBA Code:
Set wb1 = Workbooks.Open(Filename:=fileNameAndPath)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,529
Messages
6,120,070
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