I have a series of connected workbooks that work something like this:
BookA.xls remains open and once per hour it opens BookB.xls
BookB.xls opens BookC.xls and copies a range of data into BookB.xls.
BookB.xls closes BookC.xls.
BookB.xls does a SaveCopyAs BookD.xls.
BookB.xls closes BookC.xls.
My problem it that every time this series of events occurs, I end up with an additional copy of BookB and BookC in the VBA project explorer. And if I look in Tools | References I see several instances of UNSAVED BookB.
Any ideas?
Regards...Tom
Below is the routine from BookB:
Sub RetrieveSave()
'On Error GoTo BugOut
Dim wbPMO, wbPlots, myPath, myWebPath As String
Dim myDateRange As String
Dim myValSource, myValDestination As String
myPath = "O:\Process Engineering\PMO\ConsolePMO\EII\"
myWebPath = "O:\Process Engineering\PMO\ConsolePMO\EII\EII_Hourly_Plots.xls"
wbPMO = "EII_Console_PMO.xls"
wbPlots = Application.ThisWorkbook.Name
myDateRange = "A11:A515"
myValSource = "BB6:DS515"
myValDestination = "B6"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Open the PMO workbook
Application.StatusBar = "Opening file " & myPath & wbPMO
Workbooks.Open Filename:=myPath & wbPMO, UpdateLinks:=0
'Copy the EII dates from the EII Console PMO workbook
Application.StatusBar = "Copying dates from " & wbPMO
Application.Workbooks(wbPMO).Activate
Sheets("Hourly Calcs EII").Activate
Range(myDateRange).Select
Selection.Copy
'Paste the EII data into EII Charts workbook
Application.StatusBar = "Pasting dates to " & wbPlots
Application.Workbooks(wbPlots).Activate
Sheets("Data").Activate
Range(myDateRange).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy the EII values from the EII Console PMO workbook
Application.StatusBar = "Copying values from " & wbPMO
Application.Workbooks(wbPMO).Activate
Sheets("Hourly Calcs EII").Activate
Range(myValSource).Select
Selection.Copy
'Paste the EII values into EII Charts workbook
Application.StatusBar = "Pasting values to " & wbPlots
Application.Workbooks(wbPlots).Activate
Sheets("Data").Activate
Range(myValDestination).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Close the PMO workbook
Application.StatusBar = "Closing " & myPath & wbPMO
Workbooks(wbPMO).Close SaveChanges:=False
'Call the chart formatting routine
Application.StatusBar = "Adjusting format of charts..."
Call AlignCharts
'Save a copy of the workbook to the web folder
Application.StatusBar = "Saving a copy to the web as " & myWebPath
Sheets("Data").Visible = False
ActiveWorkbook.SaveCopyAs myWebPath _
'Save the workbook
Application.StatusBar = "Saving " & ActiveWorkbook.Name
Sheets("Data").Visible = True
ActiveWorkbook.Save
BugOut:
Application.StatusBar = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
[/list]
BookA.xls remains open and once per hour it opens BookB.xls
BookB.xls opens BookC.xls and copies a range of data into BookB.xls.
BookB.xls closes BookC.xls.
BookB.xls does a SaveCopyAs BookD.xls.
BookB.xls closes BookC.xls.
My problem it that every time this series of events occurs, I end up with an additional copy of BookB and BookC in the VBA project explorer. And if I look in Tools | References I see several instances of UNSAVED BookB.
Any ideas?
Regards...Tom
Below is the routine from BookB:
Sub RetrieveSave()
'On Error GoTo BugOut
Dim wbPMO, wbPlots, myPath, myWebPath As String
Dim myDateRange As String
Dim myValSource, myValDestination As String
myPath = "O:\Process Engineering\PMO\ConsolePMO\EII\"
myWebPath = "O:\Process Engineering\PMO\ConsolePMO\EII\EII_Hourly_Plots.xls"
wbPMO = "EII_Console_PMO.xls"
wbPlots = Application.ThisWorkbook.Name
myDateRange = "A11:A515"
myValSource = "BB6:DS515"
myValDestination = "B6"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Open the PMO workbook
Application.StatusBar = "Opening file " & myPath & wbPMO
Workbooks.Open Filename:=myPath & wbPMO, UpdateLinks:=0
'Copy the EII dates from the EII Console PMO workbook
Application.StatusBar = "Copying dates from " & wbPMO
Application.Workbooks(wbPMO).Activate
Sheets("Hourly Calcs EII").Activate
Range(myDateRange).Select
Selection.Copy
'Paste the EII data into EII Charts workbook
Application.StatusBar = "Pasting dates to " & wbPlots
Application.Workbooks(wbPlots).Activate
Sheets("Data").Activate
Range(myDateRange).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy the EII values from the EII Console PMO workbook
Application.StatusBar = "Copying values from " & wbPMO
Application.Workbooks(wbPMO).Activate
Sheets("Hourly Calcs EII").Activate
Range(myValSource).Select
Selection.Copy
'Paste the EII values into EII Charts workbook
Application.StatusBar = "Pasting values to " & wbPlots
Application.Workbooks(wbPlots).Activate
Sheets("Data").Activate
Range(myValDestination).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Close the PMO workbook
Application.StatusBar = "Closing " & myPath & wbPMO
Workbooks(wbPMO).Close SaveChanges:=False
'Call the chart formatting routine
Application.StatusBar = "Adjusting format of charts..."
Call AlignCharts
'Save a copy of the workbook to the web folder
Application.StatusBar = "Saving a copy to the web as " & myWebPath
Sheets("Data").Visible = False
ActiveWorkbook.SaveCopyAs myWebPath _
'Save the workbook
Application.StatusBar = "Saving " & ActiveWorkbook.Name
Sheets("Data").Visible = True
ActiveWorkbook.Save
BugOut:
Application.StatusBar = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
[/list]