Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer Control between workbooks

Status
Not open for further replies.

donjohnson

Programmer
Jun 23, 2004
53
Hello!
I have a driver workbook with an application main menu. Once the user has selected their function and been validated, I would like to transfer control to another workbook I will open, and then close the main menu workbook for others to use (thus reducing update contention issues).

I can open the second workbook (actually a new workbook from a template), but how do I pass control to a macro there, and close the workbook I started from?

Thanks!

Don
 
Don,

Have the LAST step of the code in Workbook 1 open Workbook 2. Then have code in the Workbook_Open event (or in an Auto_Open sub) of Workbook 2 take over, closing Workbook 1 and doing whatever else it needs to do.

VBAjedi [swords]
 
Thanks VBAJedi; now how would I handle it if I have to do a WB.Add, with filename, title etc.?

I have it this way:
Code:
strDir = Application.DefaultFilePath
strFile = strDir & "\" & VBA.Environ("USERNAME") & ".xls"
If FileExists(strFile) Then
    Set oDataWB = Workbooks.Open(strFile)
    MsgBox strFile & " exists"
Else
    Set oDataWB = Workbooks.Add(strDir & "\DPRDataTemplate.xlt")
    With oDataWB
        .Title = "Production Reporting Workbook"
        .SaveAs Filename:=strFile
    End With
End If

in a common subroutine.

Will I get into trouble because I am not in my main subroutine?

Don




 
I have hit an impasse with the transfer; I can open a new workbook, and close the old, but can't continue with the script in the new book to fire the new forms.

Unfortunately, the driver sheet is 77K, and the child process is over 150K with two forms. How can I have someone look at the code to help me? B-(

Thanks!

Don
 
did you find a solution to this - i have the same problem - on closing the first workbook the code running in Auto_open of the second workbook stops!
 
You need the .RunAutoMacros method when you open the 2nd workbook containing an auto open routine.

Try this to open the 2nd workbook.

Workbooks.Open(Filename:="SayHello.xls").RunAutoMacros Which:=xlAutoOpen

ThisWorkbook.close SaveChanges:=False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top