Solved

Call a sub on WS Activation

Posted on 2011-02-11
12
312 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
Technology Partners: 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!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

752 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