Solved

Call a sub on WS Activation

Posted on 2011-02-11
12
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

617 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