Hi All
I don't know if what I'm trying to achieve is possible, but basically I have a template file that does a bunch of stuff, at the end of the process, it saves as a completely new .xlsm file (thus the new file retains all the code).
What I want to achieve is that from the users point of view, in the main menu form, they click the button and it does its stuff, saves the new file, closes the template file and opens the new file loading up the main menu again.
Here is my code thus far which isn't working:
'##### Creating new master file, closing template file #################
ThisWorkbook.Sheets("Settings").Range("A2").Value = 1
InstallPath = ThisWorkbook.Sheets("Settings").Range("A1").Value & "\"
MPONo = ThisWorkbook.Sheets("Master").Range("D6").Value
CurDate = Format(Date, "yyyy.mm.dd")
On Error Resume Next
MkDir InstallPath & "MPO Masters"
On Error GoTo 0
MasterSavePath = InstallPath & "MPO Masters\" & MPONo & " " & CurDate
MkDir MasterSavePath
ThisWorkbook.SaveAs Filename:=MasterSavePath & "\" & MPONo & " Master File - " & CurDate & ".xlsm"
Workbooks.Open MasterSavePath & "\" & MPONo & " Master File - " & CurDate & ".xlsm"
Application.Run "'" & MasterSavePath & "\" & MPONo & " Master File - " & CurDate & ".xlsm" & "'!" & "Startup"
ThisWorkbook.Close
'########################################################################
Display More
Ideally just opening the new saved workbook would start this code:
Private Sub Workbook_Open()
If IsEmpty(ThisWorkbook.Sheets("Settings").Range("A1").Value) Then
MsgBox "No installation folder detected, please enter settings and set installation folder path.", vbExclamation, "No Installation Detected"
Else
End If
If ThisWorkbook.Sheets("Settings").Range("A2").Value = 0 Then
With Menu
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Else
If ThisWorkbook.Sheets("Settings").Range("A2").Value = 1 Then
With Menu1
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Else
End If
End If
End Sub
Display More
But it wasn't the new workbook would open and the template file would close, but the new workbook would not run its Workbook_Open code.
So then I tried adding an identical code into a module, and have the template file call that module when opening the new workbook:
Public Sub Startup()
If IsEmpty(ThisWorkbook.Sheets("Settings").Range("A1").Value) Then
MsgBox "No installation folder detected, please enter settings and set installation folder path.", vbExclamation, "No Installation Detected"
Else
End If
If ThisWorkbook.Sheets("Settings").Range("A2").Value = 0 Then
With Menu
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Else
If ThisWorkbook.Sheets("Settings").Range("A2").Value = 1 Then
With Menu1
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Else
End If
End If
End Sub
Display More
But that didn't work either, the new workbook opens and does nothing, and the template file closes. Thus the user is left sitting with a spreadsheet and no user form main menu showing.
Is this possible?
Regards