Solved

Call a sub on WS Activation

Posted on 2011-02-11
12
311 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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