Possible to access workbook properties in VBA?

JasonC71

Board Regular
Joined
Feb 10, 2008
Messages
159
Hi,

I have a need to for some code to check what workbook the code is being run on....in other words...I need it to say "if the ActiveWorkbook is X then do the following, else, do this." The thing is, I can't use workbook X's Name, as it changes quite frequently....so i'm looking for another way to check and see if workbook x is the active workbook. Under workbook properties, you have things like Author, Subject, etc. Can I call these properties from within a macro to check and see if the workbook in question is my special "X" workbook? (The name of the workbook may change, but the subject line in properties will not and is unique.)

Thanks,
Jason
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,344
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
You can use:
Code:
ActiveWorkbook.BuiltinDocumentProperties("Subject")
HTH
 
Upvote 0

JasonC71

Board Regular
Joined
Feb 10, 2008
Messages
159
Thanks!!

I'll give that a try tonight...I tried to capture that with the macro recorder, but got nothing....thanks for the info.

Jason
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,344
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
In case it's of interest, you can also add your own custom document properties to workbooks and check for those.
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,344
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Via the Custom tab in the Properties dialog. You can then check them using the ActiveWorkbook.CustomDocumentProperties collection in code, similar to the above. Let me know if you need more detail.
 
Upvote 0

Forum statistics

Threads
1,190,613
Messages
5,981,939
Members
439,744
Latest member
Lazerbeakk

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
Top