Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have two workbooks - I'll call them Main and Compliance. Compliance is used
solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could always have it loop through the workbooks collection and examine
each workbook to find a unique identifying characteristic. Assume only the main workbook will have a defined name "Main" Dim bk as workbook, nm as Name for each bk in application.workbooks on error resume next set nm = bk.Names("Main") On error goto 0 if not nm is nothing then bk.activate end if Next -- Regards, Tom Ogilvy "DRK" wrote: I have two workbooks - I'll call them Main and Compliance. Compliance is used solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My problem is they renamed the Main workbook to "Watson". Within "Watson" can
I set a variable to the workbook's name and pass that value to the Compliance workbook? -- DRK "Tom Ogilvy" wrote: You could always have it loop through the workbooks collection and examine each workbook to find a unique identifying characteristic. Assume only the main workbook will have a defined name "Main" Dim bk as workbook, nm as Name for each bk in application.workbooks on error resume next set nm = bk.Names("Main") On error goto 0 if not nm is nothing then bk.activate end if Next -- Regards, Tom Ogilvy "DRK" wrote: I have two workbooks - I'll call them Main and Compliance. Compliance is used solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
basically, you can have 1)public variable with workbook name 2)pass the name as one of arguments while calling your printing procedure Regards, Ivan |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You said:
My custom menu in Main calls a print macro in Compliance. Is this a commandbar button? What do you mean by custom menu what do you mean by calls a print macro in compliance A public variable in Main will not be visible in Compliance unless you set a reference from Compliance to main, so I don't know what Ivan is suggesting there. I don't see a reference as being feasible in the situation you describe. Passing an argument is not really supported if this is a commandbar button. If you are calling a procedure in Compliance from a procedure in Main using application.run, then you could pass an argument, but your description didn't seem to indicate this. Again, your participation in describing the particulars is applicable. So maybe if you provide some more information you can get a suggestion that is compatible with your situation. The suggestion I provided is applicable in any imaginable scenario by the way. -- Regards, Tom Ogilvy "DRK" wrote: My problem is they renamed the Main workbook to "Watson". Within "Watson" can I set a variable to the workbook's name and pass that value to the Compliance workbook? -- DRK "Tom Ogilvy" wrote: You could always have it loop through the workbooks collection and examine each workbook to find a unique identifying characteristic. Assume only the main workbook will have a defined name "Main" Dim bk as workbook, nm as Name for each bk in application.workbooks on error resume next set nm = bk.Names("Main") On error goto 0 if not nm is nothing then bk.activate end if Next -- Regards, Tom Ogilvy "DRK" wrote: I have two workbooks - I'll call them Main and Compliance. Compliance is used solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Tom,
Sorry I wasn't clear. I meant that public variable in Compliance (which is always the same workbook) may be visible to Main (with reference to Compliance) and that it is possible to assign value to it from Main. Regards, Ivan |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You don't need to pass the workbook name. Give your Main project
a new Project Name (in VBA, with the Main project active, go to the Tools menu, choose "VBAProject Properties" and give the project a new name like MainProject). Then, in the Compliance workbook code, use Application.VBE.VBProjects("MainProject").VBCompon ents("ThisWorkbook").Activate -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "DRK" wrote in message ... I have two workbooks - I'll call them Main and Compliance. Compliance is used solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I had to turn on "Trust access to Visual Basic Project " and then it worked.
-- DRK "Chip Pearson" wrote: You don't need to pass the workbook name. Give your Main project a new Project Name (in VBA, with the Main project active, go to the Tools menu, choose "VBAProject Properties" and give the project a new name like MainProject). Then, in the Compliance workbook code, use Application.VBE.VBProjects("MainProject").VBCompon ents("ThisWorkbook").Activate -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "DRK" wrote in message ... I have two workbooks - I'll call them Main and Compliance. Compliance is used solely to print the legal compliance stuff. Main handles the concept stuff and printing the concept stuff. My custom menu in Main calls a print macro in Compliance. When that macro is done, I want to activate the Main workbook. The problem is the Main Workbook name can be different so I can't hard code the name into Compliance code to activate the Main workbook. The end users want to save each Main workbook under a different name to preserve their cases. How can I send or carry over the name of the Main workbook with what ever is its current name to the Compliance workbook? -- DRK |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to check workbook is already opened before passing the workbook obj to a subroutine in Word | Excel Programming | |||
why is an Excel file called a workbook? | Excel Discussion (Misc queries) | |||
Reference code in another workbook from a calling workbook | Excel Programming | |||
Worksheet_Activate Not Called When Opening Workbook | Excel Programming | |||
Worksheet_Activate Not Called When Opening Workbook | Excel Programming |