PDA

View Full Version : repeate open event



lior03
02-06-2007, 11:21 AM
hello
at some stage i want excel to reperfom the workbook open event again.
as i call recall this could be doen .please explain how?.
thanks

matthewspatrick
02-06-2007, 11:48 AM
Moshe,

You can do it very easily. If the code recalling Workbook_Open is in the ThisWorkbook module, then simply make a call to that macro.

If the salling code is not in that module, the same thing applies, only now you need to declare Workkbokk_Open as Public rather than Private.

lior03
02-06-2007, 12:13 PM
hello
whats wrong with

Sub repeateve()
With ActiveWorkbook
.RunAutoMacros (xlAutoOpen)
End With
End Sub

matthewspatrick
02-06-2007, 12:15 PM
That code only works on "old-style" auto macros such as Auto_Open.

Bob Phillips
02-06-2007, 12:18 PM
hello
whats wrong with

Sub repeateve()
With ActiveWorkbook
.RunAutoMacros (xlAutoOpen)
End With
End Sub



Because that runs Auto_Open not Workbook_Open.

lior03
02-06-2007, 12:51 PM
hello
how do i get to the auto _open event?
thanks

CBrine
02-06-2007, 01:22 PM
I would suggest to add a new module to your workbook, create your macro in this new module, and call this macro from the workbook_open event and from whatever other macro code you want to use.

Patrick,
I've never messed with the Workbook_open event scope, but if you make it public, could it it be called by another workbook that is opened because of scope issues created by the public declaration?

HTH
Cal

Andy Pope
02-06-2007, 01:35 PM
You need to create the routine yourself in a standard code module. As the others have already said this is the old way before events where added.

Public Sub Auto_open()
MsgBox "Hello World"
End Sub


Maybe the easiest way is to remove the code from the Workbook_Open event and place it in a standard code module. You can then call it at any time you want. And in the Open event you call the code too.

Code in Thisworkbook module
Private Sub Workbook_Open()

Call StartUpCode

End Sub

Standard code module
Public Sub StartupCode()

' do your stuff ....

End Sub

Bob Phillips
02-06-2007, 03:55 PM
I would suggest to add a new module to your workbook, create your macro in this new module, and call this macro from the workbook_open event and from whatever other macro code you want to use.

Patrick,
I've never messed with the Workbook_open event scope, but if you make it public, could it it be called by another workbook that is opened because of scope issues created by the public declaration?

HTH
Cal

Yes, the procedure does then get exposed, but it would have to be explicitly run



Application.Run "'myWorkbook.xls'!ThisWorkbook.Workbook_Open()"