?
Solved

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

Posted on 2014-03-31
6
Medium Priority
?
494 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 31

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 31

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 31

Accepted Solution

by:
gowflow earned 1500 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

Industry Leaders: 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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