Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

604 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