Solved

Copying code to the "ThisWorkbook" module of a spun off sheet

Posted on 2014-03-31
6
467 Views
Last Modified: 2014-05-08
I have a macro that spins off each of 12 sheets ("Sheets(i).Copy"). I'm trying to track any future saves of the new workbook with a time and author stamp. To do that I need to copy this macro into the new book:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Usr As String
Usr = WorksheetFunction.VLookup(Environ("Username"), [Users], 2, 0)
[N1] = "Last saved by " & Usr & " @ " & Format(Now, "h:mm AM/PM") & " on " & Format(Now, "m/d/yyyy")
ActiveWorkbook.Save
End Sub

Open in new window

This is my ImportModule code:
Sub ImportModule()
Dim xMod As String
xMod = "H:\Depts\css\A_ILS & Reliability\Reliability\1-CURRENT\System Reporting\SDAE\WeeklySummaries\Macros\ThisWorkbook.cls"
ActiveWorkbook.VBProject.VBComponents.Import xMod
End Sub

Open in new window

And this is the code I want to import into the ThisWorkbook module:
Sub WhoSavedMe()
Dim Usr As String
Usr = WorksheetFunction.VLookup(Environ("Username"), [Users], 2, 0)
[N1] = "Last saved by " & Usr & " @ " & Format(Now, "h:mm AM/PM") & " on " & Format(Now, "m/d/yyyy")
ActiveWorkbook.Save
End Sub

Open in new window

VBA allows me to export the ThisWorkbook module as a .cls file which upon import creates a class module named "ThisWorkbook1," which of course doesn't help.

How do I accomplish my goal? I suppose I could just save the whole workbook named after each of the tabs in succession - deleting all but that one sheet - but then I'd have to re-open the main workbook 11 more times.

Thanks,
John
0
Comment
Question by:gabrielPennyback
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39968706
You are telling us how you envision your problem to be resolved and what you are trying to do which is fine.

I am missing what are you trying to achieve. You mentioned:

I'm trying to track any future saves of the new workbook with a time and author stamp.

Can you please explain in couple of sentences what do you need to achieve as it is not clear to me.

gowflow
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 39970012
Sure. Once I've created the 12 new workbooks (each one containing one of the 12 worksheets in my source workbook), different people will be working on each of the new workbooks. I want to be able to track who made revisions and when they made them, and most importantly who made the latest revision.

Each workbook will have the named range "Users," which will contain the lookup table to give me the user's actual name. To track multiple revisions I'll change the target cell in the 1st code snippet above from [N1] to [N1].End(xlDown).Offset(1,0).  

I think part of the confusion is that I shouldn't have included Code snippet 3, since the code works only if it's in the ThisWorkbook module!

Please let me know if I still need to clarify more.

Thanks,
John
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39971602
can you pls post a sample of the workbook that contain code and contain these 12 worksheets as I cannot still envision the whole thing !
Sorry I am known to be very slow ... bear with me

gowflow
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:gabrielPennyback
ID: 39984152
Hi gowflow, I guess I'll have to strip out the proprietary information but I'll post something as soon as I get past the next couple of days' deadlines. Slow and successful is better than fast and faulty :- )

Thanks,
John
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39985442
Absolutely and totally agree as I can conquer with 'Deadlines' that sometimes as so stressful that one literally looses its own name !!

Take care and let me know.
gowflow
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 40052262
Hi gowflow, sorry for being AWOL for the last month. This has become very back burner so I want to award you the points just for being so willing to help.  Thanks!  John
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

757 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

20 Experts available now in Live!

Get 1:1 Help Now