How to restrict the excel sheet containing Chart

  • Thread starter Thread starter kvenku
  • Start date Start date
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
 
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)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top