View Single Post
  #3   Report Post  
Peter
 
Posts: n/a
Default

Hi Norman,
Thanks for the reply..
This seems to work well, but it only works for page 1. If there is data on
page 2 or more it saves the whole book still.

This is the code I use when exiting Excel to autosave the workbook.

Private Sub Workbook_BeforeClose(cancel As Boolean)

Dim savepath As String
savepath = "c:\company\invoice\"
ActiveWorkbook.SaveAs Filename:=savepath & Range("AA4").Value & ".xls"

End Sub

I can't see why it's not working. I tried to integrate your code with this,
but with no further success.

Regards
Peter

"Norman Jones" wrote:

Hi Peter,

Try:

Sub sTester()
Dim sh As Worksheet
Const sTestCellAddress As String = "AA4"

On Error GoTo XIT
Application.DisplayAlerts = False
For Each sh In ThisWorkbook.Worksheets
With sh
If IsEmpty(.Range(sTestCellAddress )) Then
.Delete
End If
End With
Next sh

XIT:

Application.DisplayAlerts = True

End Sub

---
Regards,
Norman



"Peter" wrote in message
...
Hello All,

I am trying to figure out how to search a certain cell range (AA4), on
each
of upto 30 worksheets in the same workbook. Then if it finds that range to
be
empty (ie: the page has not been used) delete it when exiting.

My workbook autosaves a file on exit using the same cell range on the
first
worksheet as it's filename.

Regards
Peter