Workbook name, easy one for most everyone but me..

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
577
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the following in a macro. In an open workbook event, I place the workbook name into cell "F1" on "Sheet1". I have a Workbook_WindowResize event that I want to "Set wbk =" to the workbook in cell "F1" (the workbook name). I have the whole workbook name in the first code below, but I want to write it such that I don't have to put the workbook name in this code. I hope some of this makes sense. SS

VBA Code:
Dim wbk As Workbook
Set wbk = Workbooks("BAS - Shop Folder Time Tracking Details - 8-18-2023.xlsm")



VBA Code:
Dim wbk As Workbook
Set wbk = Range("F1")
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
That is because you are trying to set a range equal to a workbook variable!

You need to do it like this:
VBA Code:
Set wbk = Workbooks(Range("F1").Value)
assuming the value in F1 is accurate.
 
Upvote 0
Solution
That is because you are trying to set a range equal to a workbook variable!

You need to do it like this:
VBA Code:
Set wbk = Workbooks(Range("F1").Value)
assuming the value in F1 is accurate.
Does the entire name and file path have to be in "F1" or just the file name to meet the requirement of the wkb?
 
Upvote 0
Does the entire name and file path have to be in "F1" or just the file name to meet the requirement of the wkb?
Test it out and find out! ;)
(Should be pretty easy to test it out).
 
Upvote 0
That means it couldn't find it.

F1 should have something in that looks like this:-
BAS - Shop Folder Time Tracking Details - 8-18-2023.xlsm

And that workbook needs to be already open.
 
Upvote 0
You have to use the SaveAs method to change the name of a Workbook.
 
Upvote 0
Test it out and find out! ;)
(Should be pretty easy to test it out).
I finally got it to work. Not sure what I was doing wrong after I changed it to what you suggested because it still wouldn't work. Then all of a sudden it did work. I did close the file and open it on a different computer though. Weird. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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