ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using - Private Sub Workbook_Open()" (https://www.excelbanter.com/excel-programming/414920-using-private-sub-workbook_open.html)

SANDIND

Using - Private Sub Workbook_Open()"
 
Hi All,

Can we use more than once "Private Sub Workbook_Open()" in one workbook. I
am trying to use to such written macros but I am getting error for the second
one. i was wondering is that only once we can use this.

I am new to VB plz help and Thanks in advance.

SS

FSt1

Using - Private Sub Workbook_Open()"
 
hi
only one workbook_open can be use that i am aware of.
if you have 2 macros that you want to run at open you can...
combine the 2 into one
or use the call command in the workbook open macro to call the second.

regards
FSt1

"SANDIND" wrote:

Hi All,

Can we use more than once "Private Sub Workbook_Open()" in one workbook. I
am trying to use to such written macros but I am getting error for the second
one. i was wondering is that only once we can use this.

I am new to VB plz help and Thanks in advance.

SS


SANDIND

Using - Private Sub Workbook_Open()"
 
Thanks to both of you,

for your quick response, and giving such a valuable suggestion.

Have a great day..

"Chip Pearson" wrote:

You can have only one _Open event procedure in the ThisWorkbook module, and
that event is called only when the workbook containing the code is opened.
It does not trigger when other workbook are opened. If you need to detect
another workbook being opened (either a new workbook or an existing
workbook, you need to use code like the following:

Option Explicit

Private WithEvents App As Excel.Application

Private Sub Workbook_Open()
Set App = Application
End Sub

Private Sub App_NewWorkbook(ByVal Wb As Workbook)
' called when a new workbook is created.
End Sub

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
' called when an existing workbook is opened.
End Sub

For more info on Application events, see
http://www.cpearson.com/Excel/AppEvent.aspx .


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"SANDIND" wrote in message
...
Hi All,

Can we use more than once "Private Sub Workbook_Open()" in one workbook. I
am trying to use to such written macros but I am getting error for the
second
one. i was wondering is that only once we can use this.

I am new to VB plz help and Thanks in advance.

SS




All times are GMT +1. The time now is 09:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com