saving an excel worksheet


Posted by Tom on January 09, 2002 4:32 AM

Description of the Ebook problem with the onepage macros:

When running the Agency State 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 and Branch with the Save As code in red.

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 GETS EXECUTED BUT DOESN'T SAVE
ActiveWorkbook.Close
ActiveWorkbook.Close
End Sub



Posted by Dan on January 09, 2002 5:38 AM

Your question was answered in your previous post