Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is there a simple way to determine if an open workbook has any data?
Maybe the used range = nothing? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Nigel,
Try this, from an other workbook using the name of the workbook you want to check as parameter Public Function IsWorkBookEmpty(aWorkbook As Workbook) As Boolean Dim sht As Worksheet Dim bln As Boolean bln = True For Each sht In aWorkbook.Sheets If sht.UsedRange.Cells.Count 1 Then bln = False Exit For Else If Not IsEmpty(sht.Range("A1")) Then bln = False Exit For End If End If End If If bln Then If aWorkbook.Charts.Count 0 Then bln = False Exit For End If End If End Function HTH, RadarEye On 22 sep, 13:06, Nigel RS wrote: Is there a simple way to determine if an open workbook has any data? Maybe the used range = nothing? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks with modification it works ok.
I had to assign the bln to the function name to get the returned value, change the usedrange count logical test to 0 not 1, fix the for next loop and remove the extra code in the charts count area. So I ended up with Public Function IsWorkBookEmpty(aWorkbook As Workbook) As Boolean Dim sht As Worksheet Dim bln As Boolean bln = True For Each sht In aWorkbook.Sheets If sht.UsedRange.Cells.Count 0 Then bln = False Exit For Else If Not IsEmpty(sht.Range("A1")) Then bln = False Exit For End If End If Next If bln And aWorkbook.Charts.Count 0 Then bln = False IsWorkBookEmpty = bln End Function "RadarEye" wrote: Hi Nigel, Try this, from an other workbook using the name of the workbook you want to check as parameter Public Function IsWorkBookEmpty(aWorkbook As Workbook) As Boolean Dim sht As Worksheet Dim bln As Boolean bln = True For Each sht In aWorkbook.Sheets If sht.UsedRange.Cells.Count 1 Then bln = False Exit For Else If Not IsEmpty(sht.Range("A1")) Then bln = False Exit For End If End If End If If bln Then If aWorkbook.Charts.Count 0 Then bln = False Exit For End If End If End Function HTH, RadarEye On 22 sep, 13:06, Nigel RS wrote: Is there a simple way to determine if an open workbook has any data? Maybe the used range = nothing? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Extra empty workbook opens up when any excel file is open | Excel Discussion (Misc queries) | |||
Open a specific workbook...find value from other open workbook and then insert cells values in cell next to it. | Excel Programming | |||
Open workbook to same worksheet and next empty row | Excel Worksheet Functions | |||
How do I open a empty workbook with no sheets? | Excel Programming | |||
How to avoid opening an empty workbook every time I open a file? | Setting up and Configuration of Excel |