Solved

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

Posted on 2014-03-31
6
484 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

734 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