How to determine if a chart is embedded or not
Hello Peter,
thanks very much to you and Barb for the prompt reply! My VBA skills
are somewhat limited, so I'd like to ask you a couple of questions:
On 21 Gen, 12:02, "Peter T" <peter_t@discussions wrote:
Several ways, one way would be to check if SheetName refers to a chart
sheet, eg
Function IsChartSheet(SheetName) As Boolean
Dim cht As Chart
* * On Error Resume Next
^^^^^^^^^^^^^^^^^^^^^^^^^
What's this? I've seen this construct some other times, usually in the
form
On Error Resume Next
(do something)
On Error GoTo 0
and then there's no label 0 in all the code(!). Is this VBA way of
handling errors? Does it have something to do with OO coding? I come
from a Fortran background and I'm not sure what's going on here.
* * Set cht = ActiveWorkbook.Charts(SheetName)
* * IsChartSheet = Not cht Is Nothing
I don't understand this piece of code...
End Function
Note also, although unusual it's possible for a chartsheet (ie a chart) to
include one or more embedded charts.
Does this mean that my code + your code will not be able to tell if
ChartName corresponds to an embedded chart or a chart, in the case of
a chart embedded in another chart? Or will it work anyway?
Regards,
Peter T
Thanks again, and one last question: can you suggest a good Excel/VBA
book to study VBA programming in Excel?
Best Regards
Sergio
"deltaquattro" wrote in message
...
Hi guys,
a question for you Excel VBA experts. I wrote the following function
which applies formatting to a chart:
Function FormatAxes(Optional SheetName As String, Optional ChartName
As String, _
Optional IsEmbedded As Boolean, _
Optional Xmin, Optional Xmax, Optional Ymin, Optional Ymax, Optional
XMinorUnit, _
Optional XMajorUnit, Optional YMinorUnit, Optional YMajorUnit)
Dim xlChart As Chart
* *If SheetName = vbNullString Then SheetName = ActiveSheet.Name
* *If ChartName = vbNullString Then ChartName = ActiveChart.Name
* *If IsEmbedded Then
* * * *Set xlChart = Worksheets(SheetName).ChartObjects
(ChartName).Chart
* *Else
* * * *Set xlChart = Charts(ChartName)
* *End If
....
End Function
As you can see, i tried to wrote it in such a way that the code would
work also if the sheet name and chart name are not given in input: in
that case, the code usese the active sheet and active chart. Then I
realized that such a code would work only on embedded charts, so I
added the IsEmbedded optional parameter, which tells the code if the
chart is embedded or not. However, I'd really prefer the code to
determine by itself if the chart is embedded or not, rather than
relying on the user to supply the correct value for the IsEmbedded
optional parameter. Could you please help me do this? Thank you very
much,
Best Regards
Sergio Rossi
ps if anybody is interested in the full code of the function, and/or
its goal, feel free to ask :)
|