Solved

VBA to check if charttype is 3D

Posted on 2011-09-05
4
377 Views
Last Modified: 2012-05-12
Hi Experts

I want to create a macro that checks if the chart a user has created is in 3D - I know there is a chartype property of chart, but this returns a number, does anyone have a list of numbers or is there a simpler way  -
currently I have

If InStr(UCase(mcht.ChartType), "3D") > 0 Then
       
            MsgBox "3D"
        End If
       
but as the charttpe is a number its not working, when selecting a charttype I can type in text
0
Comment
Question by:MrDavidThorn
  • 2
4 Comments
 
LVL 15

Expert Comment

by:CSLARSEN
ID: 36485093
Hi
You can check for the number in chart type.

Check a list of chartypes, e.g. http://it.toolbox.com/wiki/index.php/EXCEL_Chart_Type_Enumeration
Another more complete but also less elegant would be to insert all 3D numbers in an array to validate the selected charttype against.
However from my point of view you are not using a poor proxy for 3D identification.
Cheers
cslarsen
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 36485124
Here is a function that incorporates the numbers suggested by CSLARSEN. It returns TRUE if the ChartType is one of the 3D types. Install it in a regular module, or incorporate the logic in your sub.

Function IsChart3D(co As ChartObject) As Boolean
Select Case co.Chart.ChartType
Case -4102 To -4100, -4098, 54 To 56, 60 To 62, 78 To 79
    IsChart3D = True
End Select
End Function

Open in new window

0
 
LVL 15

Expert Comment

by:CSLARSEN
ID: 36485406
Nice one byundt
learned the compact array/case part
thx carsten
0
 

Author Closing Comment

by:MrDavidThorn
ID: 36485466
thanks guys
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now