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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,215,262
Messages
6,123,939
Members
449,134
Latest member
NickWBA

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