How to restrict the excel sheet containing Chart

K

kvenku

Hi ,
I have created a macros where it contains commondialog control whic
is used to open xls files for some purpose.

I want to restrict if the xls contains chart in it. Is this possible.

I need to open the file which contains onlu datas. No other file shoul
open.

How to do it.

Please help me out.

Thanks

venkatesh
 
B

Bob Phillips

The only way I could see this working is if you used a naming convention
that identified which files had charts, and then used a filter on this
value.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

Dave Peterson

You could check to see if that workbook had any charts in it before your code
continued:

Option Explicit
Function hasCharts(wkbk As Workbook)

Dim sh As Object
Dim FoundOne As Boolean

FoundOne = False
For Each sh In wkbk.Sheets
If LCase(TypeName(sh)) = "worksheet" Then
If sh.ChartObjects.Count > 0 Then
FoundOne = True
Exit For
End If
ElseIf LCase(TypeName(sh)) = "chart" Then
FoundOne = True
Exit For
End If
Next sh

hasCharts = FoundOne

End Function


Sub testme01()

If hasCharts(ActiveWorkbook) = False Then
MsgBox "no charts"
Exit Sub
End If

'existing code here

End Sub
 
Top