active workbook name - new workbook name?

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
So I entered the code below into my personal.xls thisworkbook section in hopes that every time a new workbook opens i would get me the name of the new workbook displayed. But no, the first time it gives me "Personal.xls" subsequent newly opened work book it does not respond at all.

Any ideas how I can do this?

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Private Sub Workbook_Open()
twn=thisworkbook.name
awn=activeworkbook.name
msgbox twn
msgbox awn
end sub
[/FONT]
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It looks like your code is functioning like it should.

The below event only fires when the workbook it is located in is opened (it is a workbook level event). Since yours is in personal.xls, it only fires once when excel is run and it opens the personal.xls file.
Code:
[COLOR=#333333]Private Sub Workbook_Open()[/COLOR]

To do what you're describing, you would need to capture the WorkbookOpen event at the application level. The below 2 links give a nice description of how this works -- it is a lot more complicated than the workbook level events. If you give a little more detail on why you are trying to do what you described, there may be an easier way around it, but to purely capture the name of a workook as it is opened, I think you might be stuck with the application level event.

https://bettersolutions.com/vba/events/excel-application-level-events.htm
https://bettersolutions.com/excel/macros/application-level-events.htm
 
Upvote 0
Thank for the help. I have one wb that I open many m,any times a day. I am trying to specify the location and size so it will always open in the same unused section of my screens. This works, except then every other workbook opens on top of it at that size. So I was trrying to make it active only for that one workbook.
 
Upvote 0
I went ahead and setup an add-in file that will function like your first post described -- msgboxing name of any workbook that is opened.
You can download it from the link below.
To get it to work, you will need to unzip the .xla file, then in Excel enable the add-in by going to file->options->add ins-> excel add ins-> go.
Once enabled the file will run every time excel is run until you disable it.
To modify the code, in the code editor window, you will see a class module folder with one class module in it. Open that up, and you will see the 2 events below. You will need to modify both of those identically. It turns out that workbookOpen only works for existing workbooks, so you need the newWorkbook one to handle any brand new workbooks.



Code:
Private Sub excel_events1_NewWorkbook(ByVal Wb As Workbook)    'fires when a brand new workbook is opened
    MsgBox Wb.Name
    
End Sub


Private Sub excel_events1_WorkbookOpen(ByVal Wb As Workbook)
    'fires when an existing workbook is opened
    MsgBox Wb.Name
End Sub

http://s000.tinyupload.com/?file_id=53071202495837314834
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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