Excel not saving the active workbook


Posted by Tom on January 08, 2002 7:33 AM

Description of the Ebook problem with the onepage macros:

When running the Agency State and the Branch onepage macro the macro does not save the spreadsheets. Going through the procedure in debug mode the code looks like it executes the Save As command however the spreadsheets do not get saved. A temporary solution was to run it in debug mode then click on the first spreadsheet and physically do a File Save As. After the first spreadsheet was saved the macro was rerun and it worked correctly. The same drill had to be done on the Branch onepage. It runs on a Windows 95 system with excel 97. Below is the code for the Agency State.

Agency State Onepage

Sub main_onepage_agstate()

ChDir "y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\onepage"
Workbooks.Open FileName:= _
"y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\onepage\stemp" & month_abrv & ".xls"
ChDir "y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\Agency State"
Workbooks.Open FileName:= _
"y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\Agency State\" & state_name
'Windows("ebook geographics.xls").Activate
'regnum = regnums(i)
'Application.Goto "regnames" & reg_num
'Selection.Copy Range("variables")
Windows("stemp" & month_abrv & ".xls").Activate
Workbooks("ebook geographics.xls").Sheets("codes").Range("Reg_name").Copy _
Workbooks("stemp" & month_abrv & ".xls").Sheets("Data Sheet").Range("Geo")
'regnum = regnums(i)
'Application.Goto "regnames" & regnum
'Selection.Copy Range("variables")
'Windows("stemp" & month_abrv & ".xls").Activate
ActiveWorkbook.ChangeLink Name:="Countrywide.xls", _
NewName:=state_name & ".xls", Type:=xlExcelLinks
Calculate
Sheets(1).Select
Dim j As Integer
For j = 1 To Sheets.Count
If Sheets(j).Name <> "Data Sheet" Then
If Sheets(j).Name <> "O" Then
Sheets(j).Select
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Range("A1").Select
End If
End If
Next j
Sheets(Array("Data Sheet", "O")).delete
ChDir "y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\Agency State\Onepage"
ActiveWorkbook.SaveAs FileName:="s" & state_name & ".xls" ' THIS IS WHERE IT'S NOT SAVING
ActiveWorkbook.Close
ActiveWorkbook.Close
End Sub



Posted by Dan on January 08, 2002 9:52 AM

Combine the CHDir and Save as lines in your macro...

.
.
.
Sheets(Array("Data Sheet", "O")).delete
ActiveWorkbook.SaveAs FileName:="y:\Pricing\2001 E-BOOK\" & month & ") " & month_name & "\Agency State\Onepage\s" & state_name & ".xls"
ActiveWorkbook.Close
ActiveWorkbook.Close
End Sub