Solved

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

Posted on 2014-03-31
6
487 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
[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
  • 3
  • 3
6 Comments
 
LVL 30

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 30

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 30

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

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

717 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