Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to delete charts

Is it possible to create a macro that can select and delete all of the
charts in a workbook. Regardless of their names?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Macro to delete charts

This will remove chart sheets and embedded charts:

'====================================
Sub ChartsDelete()
Dim ch As Chart
Dim ws As Worksheet
Dim chObj As ChartObject
Application.DisplayAlerts = False

For Each ch In ActiveWorkbook.Charts
ch.Delete
Next

For Each ws In ActiveWorkbook.Worksheets
For Each chObj In ws.ChartObjects
chObj.Delete
Next
Next

Application.DisplayAlerts = True
End Sub
'==================================

bambam77 wrote:
Is it possible to create a macro that can select and delete all of the
charts in a workbook. Regardless of their names?


--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to delete charts

Thank you, this worked great. I have another question. I am new to thi
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from peopl
here and in the delete chart code I just received. What is this Dim
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used som
variables in some of my macros without the Dim command and they worke
fine so I'm kind of confused as to it's use.


Thank

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Macro to delete charts

Good Practice is to start your code with

OPTION EXPLICIT

then you will need to define variables with the DIM statement, but avoid
problems with duplicate names etc


"bambam77 " wrote in message
...
Thank you, this worked great. I have another question. I am new to this
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from people
here and in the delete chart code I just received. What is this Dim?
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used some
variables in some of my macros without the Dim command and they worked
fine so I'm kind of confused as to it's use.


Thanks


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Macro to delete charts

And if you use "option explicit" and dim your variables appropriately, then you
can get the VBE's intellisense to pop up for you. (Less wear and tear on the
memory!)

Try this in a test module:

Option explicit
sub testme()
Dim Wks as worksheet
'now type wks. (as soon as you hit that dot, you should see some valid choices
for what you can do to a worksheet (or a property of the worksheet that you can
examine).

This is very nice to us older folks.

And by forcing you to declare your variables, you don't have to spend hours
looking for the mistake in this code:

for xlctr = 1 to 5
msgbox x1ctr
next xlctr

(the one's and ell's are mixed up).

You would have gotten an error when you tried to compile.

And this is nice to us older folks with bifocals!


"bambam77 <" wrote:

Thank you, this worked great. I have another question. I am new to this
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from people
here and in the delete chart code I just received. What is this Dim?
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used some
variables in some of my macros without the Dim command and they worked
fine so I'm kind of confused as to it's use.

Thanks

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a sheet and access charts Jim--Kent Excel Worksheet Functions 2 April 6th 07 05:41 PM
Delete ALL Charts in a WorkSheet (VB) Corey Charts and Charting in Excel 2 October 4th 06 08:41 AM
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM


All times are GMT +1. The time now is 08:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"