Setting Open Book based on Cell.Value

Yorke

New Member
Joined
Nov 29, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
I am trying to consolidate data from some old files, I am starting with 3 files before doing all of them. All of the file names are listed in Column Z in the Data tab, so to begin with I am doing Z2:Z4, and eventually I will extend it.

For the code I have written, Excel returns 'Run-time error '424': Object Required' and highlights the Set OpenBook line.

There is quite a lot in the "other code" section which I have removed, but that section works. I have attached photos of what I can share of the cell values and file names.

Dim Cell2 As Range
Dim OpenBook As Workbook

For Each Cell2 In ThisWorkbook.Worksheets("Data").Range("Z2:Z4")

Set OpenBook = "C:\Users\Yorke\Files\" & Cell2.Value & ".xlsx"

'Other Code

Next Cell2

1651046454851.png
1651046486042.png
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Change that line to:
VBA Code:
    Set OpenBook = Workbooks.Open("C:\Users\Yorke\Files\" & Cell2.Value & ".xlsx")
 
Upvote 0
Solution

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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