R
ragtopcaddy via OfficeKB.com
I am creating, from an Access97 function, an xls file from an xls template.
The template is 17MB. I've been working on this project for a couple of days.
The first files I created were approx 27MB in size. Now, all of a sudden, for
no apparent reason, using a similar sized dataset from Access, the xls file
has ballooned to a whopping 133MB. What could be causing this, and how might
I fix it? If I don't solve this, I will have to start all over again.
Here is my entire function from Access97 VBA:
Function XLTemplate(strPath As String, strTemplate As String, strShtName As
String, _
strNmdRange As String, strRS As String,
strSavePath As String) As Boolean
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Const conMAX_ROWS = 20000
Dim strDate As String
Dim strWkBK As String
Dim strRange As String
Dim iRow As Integer
strDate = Format(Date - Choose(WeekDay(Date, vbMonday), 3, 1, 1, 1, 1, 1, 2)
, "mm_dd_yy")
strWkBK = "Paul Rpt_" & strDate & "_Repo.xls"
Set objXL = New Excel.Application
With objXL
.ScreenUpdating = False
.Visible = True
Set objWkb = .Workbooks.Open(strPath & strTemplate)
objWkb.SaveAs strSavePath & strWkBK
objWkb.CLOSE True
Set objWkb = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, strRS,
strSavePath & strWkBK, , strNmdRange
Set objWkb = .Workbooks.Open(strSavePath & strWkBK)
Set objSht = objWkb.Worksheets(strShtName)
objSht.Activate
objSht.Range(strNmdRange).Select
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
Set objSht = .Worksheets("Repo")
objSht.Select
.ActiveSheet.PivotTables("Repo_Pivot").PivotCache.Refresh
Set objSht = .Worksheets("Sub super cluster by cusip")
objSht.Select
.ActiveSheet.PivotTables("Inventory_Pivot").PivotCache.Refresh
iRow = .Range("A4").End(xlDown).Row
objSht.Range("A3").Select
Set objSht = .Worksheets("Combined")
objSht.Select
objSht.Rows(iRow & ":11001").Select
.Selection.ClearContents
.Range("A1:AO" & iRow - 2).Select
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.CutCopyMode = False
.Selection.Copy
.Sheets.Add After:=.Sheets("Assumptions")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Current"
End With
Set objSht = .Worksheets("Current")
objSht.Select
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
objSht.Cells(4, 1).Select
.Selection.AutoFilter Field:=4, Criteria1:="=GOVERNMENT", Operator:=xlOr,
_
Criteria2:="=AGENCY"
.Cells.Select
.Selection.Copy
.Sheets.Add After:=.Sheets("Current")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Agency_Govts"
End With
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
.Selection.End(xlDown).Select
.Range(.Selection, .Selection.End(xlToRight)).Select
With .Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
.Selection.End(xlLeft).Select
.ActiveCell.Offset(1, 0).Activate
objSht.Select
objSht.ShowAllData
.Selection.AutoFilter Field:=4, Criteria1:="<>GOVERNMENT", Operator:
=xlAnd _
, Criteria2:="<>AGENCY"
.Cells.Select
.Selection.Copy
.Sheets.Add After:=.Sheets("Agency_Govts")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Corp_Supra_catchall"
End With
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
.Selection.End(xlDown).Select
.Range(.Selection, .Selection.End(xlToRight)).Select
With .Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
.Selection.End(xlLeft).Select
.ActiveCell
.Range("A4").Select
objSht.ShowAllData
End With
XLTemplate = True
OuttaHere:
On Error Resume Next
objWkb.CLOSE True
objXL.ScreenUpdating = True
objXL.CutCopyMode = False
objXL.Quit
Echo True
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
End Function
Thanks,
Bill Reed
The template is 17MB. I've been working on this project for a couple of days.
The first files I created were approx 27MB in size. Now, all of a sudden, for
no apparent reason, using a similar sized dataset from Access, the xls file
has ballooned to a whopping 133MB. What could be causing this, and how might
I fix it? If I don't solve this, I will have to start all over again.
Here is my entire function from Access97 VBA:
Function XLTemplate(strPath As String, strTemplate As String, strShtName As
String, _
strNmdRange As String, strRS As String,
strSavePath As String) As Boolean
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Const conMAX_ROWS = 20000
Dim strDate As String
Dim strWkBK As String
Dim strRange As String
Dim iRow As Integer
strDate = Format(Date - Choose(WeekDay(Date, vbMonday), 3, 1, 1, 1, 1, 1, 2)
, "mm_dd_yy")
strWkBK = "Paul Rpt_" & strDate & "_Repo.xls"
Set objXL = New Excel.Application
With objXL
.ScreenUpdating = False
.Visible = True
Set objWkb = .Workbooks.Open(strPath & strTemplate)
objWkb.SaveAs strSavePath & strWkBK
objWkb.CLOSE True
Set objWkb = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, strRS,
strSavePath & strWkBK, , strNmdRange
Set objWkb = .Workbooks.Open(strSavePath & strWkBK)
Set objSht = objWkb.Worksheets(strShtName)
objSht.Activate
objSht.Range(strNmdRange).Select
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
Set objSht = .Worksheets("Repo")
objSht.Select
.ActiveSheet.PivotTables("Repo_Pivot").PivotCache.Refresh
Set objSht = .Worksheets("Sub super cluster by cusip")
objSht.Select
.ActiveSheet.PivotTables("Inventory_Pivot").PivotCache.Refresh
iRow = .Range("A4").End(xlDown).Row
objSht.Range("A3").Select
Set objSht = .Worksheets("Combined")
objSht.Select
objSht.Rows(iRow & ":11001").Select
.Selection.ClearContents
.Range("A1:AO" & iRow - 2).Select
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.CutCopyMode = False
.Selection.Copy
.Sheets.Add After:=.Sheets("Assumptions")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Current"
End With
Set objSht = .Worksheets("Current")
objSht.Select
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
objSht.Cells(4, 1).Select
.Selection.AutoFilter Field:=4, Criteria1:="=GOVERNMENT", Operator:=xlOr,
_
Criteria2:="=AGENCY"
.Cells.Select
.Selection.Copy
.Sheets.Add After:=.Sheets("Current")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Agency_Govts"
End With
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
.Selection.End(xlDown).Select
.Range(.Selection, .Selection.End(xlToRight)).Select
With .Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
.Selection.End(xlLeft).Select
.ActiveCell.Offset(1, 0).Activate
objSht.Select
objSht.ShowAllData
.Selection.AutoFilter Field:=4, Criteria1:="<>GOVERNMENT", Operator:
=xlAnd _
, Criteria2:="<>AGENCY"
.Cells.Select
.Selection.Copy
.Sheets.Add After:=.Sheets("Agency_Govts")
With .ActiveSheet
With .Cells
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
objXL.CutCopyMode = False
End With
.Name = "Corp_Supra_catchall"
End With
.ActiveWindow.DisplayZeros = False
.Selection.WrapText = False
.Cells.EntireColumn.AutoFit
.Range("A4").Select
.Selection.End(xlDown).Select
.Range(.Selection, .Selection.End(xlToRight)).Select
With .Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
.Selection.End(xlLeft).Select
.ActiveCell
.Range("A4").Select
objSht.ShowAllData
End With
XLTemplate = True
OuttaHere:
On Error Resume Next
objWkb.CLOSE True
objXL.ScreenUpdating = True
objXL.CutCopyMode = False
objXL.Quit
Echo True
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
End Function
Thanks,
Bill Reed