Solved

Call a sub on WS Activation

Posted on 2011-02-11
12
307 Views
Last Modified: 2012-05-11
Hi,

I have two Private Subs which i want to call on workbook opening.

The WS i called "Check" and is going to be very hidden.

The subs are below.

What is the best code to use to call these subs on WB opening?

Thanks
Seamus
0
Comment
Question by:Seamus2626
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34870858
Use the Workbook-Open event (in the ThisWorkbook module)?
0
 
LVL 8

Expert Comment

by:ragnarok89
ID: 34870919
The first sub in your workbook must be called   Auto_open()

Auto_open() will have 2 statements:
call x
call y

where x and y are the names of your private subs.

Al
0
 

Author Comment

by:Seamus2626
ID: 34870928
Ive tried Stephen, but it calls the subs undefined?

Cheers,
Seamus
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34870944
Seamus - can you post a sample workbook?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34871256
Why are they Private if you want to call them from another module? Make them Public instead.
0
 

Author Comment

by:Seamus2626
ID: 34871344
Hi.

I put this in the workbook opening


Public Sub Workbook_Open()
Call Workbook_BeforeClose
Workbook_Open
End Sub

I called the subs Public and it gives me the message when the file opens

"Argument Not Optional"

Thanks
Seamus
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 167 total points
ID: 34871383
Seamus - what are you trying to do? Why close the workbook when it opens and then try to open it again? (Though pretty sure you can't use workbook events like that.)
0
 

Author Comment

by:Seamus2626
ID: 34871422
Im not trying to close it Stephen, when this work book opens i want it to apply the below code.

It basically shows what time the user enters and after they close what time they left.

Thanks
Seamus
Public Sub Workbook_BeforeClose(Cancel As Boolean)
With Sheets("check")
    .Range("B64000").End(xlUp).Offset(0, 2) = Now()
End With
ActiveWorkbook.Save
End Sub

Public Sub Workbook_Open()
With Sheets("check")
   .Range("B64000").End(xlUp).Offset(1, 0) = Environ("USERNAME")
   .Range("B64000").End(xlUp).Offset(0, 1) = Now()
End With
End Sub

Open in new window

0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 167 total points
ID: 34871436
Basically, move the code you have in the BeforeClose event into a sub in a normal module and then call that sub both from the BeforeCLose event and from the Open event.

However, as Stephen asked - what are you actually trying to achieve?
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 166 total points
ID: 34872541
From the Workbook_Open event you should call a public sub, say WorkbookOpen.  Then from the Workbook_BeforeClose event run another called (say) WorkbookClose.  The code to run when the workbook is opened should be in the WorkbookOpen sub.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34872556
You might have some of the same code in these two subs.  No problem, since they are both simple.  If more is involved, you could make some more public subs and call several of them (different selections) from the WorkbookOpen and WorkbookClose subs.
0
 

Author Closing Comment

by:Seamus2626
ID: 34886777
Thanks all

Got it too work
Cheers,
Seamus
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now