473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help to write Macro to manipulate charts in workbook!

34 New Member
Hello,

I receive a workbook via 3rd party containing graphs within each sheet. The workbook may contain a different number of sheets per file.

I would like to write a macro to go through each sheet in the workbook (except for sheets 1 and 2), and change the name of the series to "Total Membership". Code I've tried to write is as such:

Sub Change ()

Dim ws As Worksheet
Workbooks.Open [NameofFile]
Application.Scr eenUpdating = False
For Each ws In ActiveWorkbook. Sheets
ActiveSheet.Cha rtObjects("Char t 1").Activate
ActiveChart.Plo tArea.Select
Application.Cut CopyMode = False
ActiveChart.Ser iesCollection(3 ).Name = "=""Total_Membe rship"""
ActiveWindow.Vi sible = False
If ws.Index <> 1 And ws.Index <> 2 Then ws.Select False
Next ws

End Sub


This code appears to go through each sheet in the file, but will only change the name of the first chart (in sheet 3), and do nothing to any other chart.

Yes, I am a novice... so any help would be appreciated!!!

Thank you,
Matt
Application.Scr eenUpdating = True
Apr 16 '08 #1
2 1591
jeffstl
432 Recognized Expert Contributor
Maybe this?

Expand|Select|Wrap|Line Numbers
  1. Sub Change ()
  2.  
  3. Dim ws As Worksheet
  4. Workbooks.Open [NameofFile]
  5. Application.ScreenUpdating = False
  6. dim x as integer
  7. x = 2
  8. For Each ws In ActiveWorkbook.Sheets
  9.      x = x+1
  10.      ActiveSheet.ChartObjects("Chart 1").Activate
  11.      ActiveChart.PlotArea.Select
  12.      Application.CutCopyMode = False
  13.      ActiveChart.SeriesCollection(x).Name = "=""Total_Membership"""
  14.      ActiveWindow.Visible = False
  15.      If ws.Index <> 1 And ws.Index <> 2 Then ws.Select False
  16. Next ws
  17.  
  18. End Sub
  19.  
This will change the active chart index number as you loop through, instead of it always being 3.

I must admit though I am not that familiar with Excel macros such as this but that basic premise should be correct
Apr 17 '08 #2
deve8ore
34 New Member
I appreciate your help... it actually guided me in the right direction.

The "3" in the code: ActiveChart.Ser iesCollection(3 ) actually represented the number of the series I wanted to change (to name "Total Membership"), so that remains constant. The correct code was:

For Each ws In ActiveWorkbook. Sheets
x = x + 1
ActiveSheet.Cha rtObjects("Char t 1").Activate
ActiveChart.Plo tArea.Select
Application.Cut CopyMode = False
ActiveChart.Ser iesCollection(3 ).Name = "=""Total_Membe rship"""
ActiveWindow.Vi sible = False
If ws.Index <> 1 And ws.Index <> 2 Then ws.Select False
If ws.Index > 2 Then ws.Select True
Next ws


Again, thank you for your help, it is appreciated!
Apr 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7193
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to get the basics down as well as some examples displaying how to simply read and write. But the next step appears exponential. I haven never done anything in VB, so any and all concepts and commands are completely foreign. I have been digging...
2
11108
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine, I know how to do this. I'm preferring to keep the Excel instance invisible, but while the macro is running, it would be nice to see some sort of progress indicator. (By the way, here's basically what the Excel macro is doing: it's opening...
2
7651
by: geronimo_me | last post by:
Hi, I have the following code in an access module: Sub Run_Excel_Macro() Dim xls, xlWB As Object Dim strFile, strMacro As String
0
967
by: Henry | last post by:
I am trying to build .NET Windows form application to manipulate data is specified Excel spreadsheets, but I am running short on information and my searches of MSDN aren't finding the data I need. I really don't know if it is better to ask here in the C# group or some Office group. I am trying to write the code in C#, but this requires knowledge of the Office Excel Object model.
0
2229
by: MNFV | last post by:
Hi, I've wrote the code GRAPHIC_ENGINE.ASPX.VB but it doesn't work properly, because the chart appears only with one dataline (the last line resulting from the query). Can anyone tell me what i'm doing wrong? Thanks in advance. Marco Viana Portugal
4
2018
by: stocki | last post by:
Hi Everybody, one of my C# apps copies charts from an Excel workbook into a table in a word document. ((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy(); myvalue = Word.WdPasteDataType.wdPasteMetafilePicture; myOutRange.PasteSpecial( ref mymissingValue, ref mymissingValue, ref mymissingValue, ref mymissingValue, ref myvalue, ref mymissingValue, ref mymissingValue );
4
3249
by: JonathanParker | last post by:
Looking for some help urgently with some VB SQL Access stuff. You'll have to excuse the messiness of the code, I'm a newbie at all this. I'm running this code with a selection of check boxes to select extra fields for my table that is then exported to Excel. there are 3 fields that are always part of the SQL, when these are selected it works fine, however when I select any of the optional fields I get a Runtime Error '3011' saying: the...
1
1215
by: shutterlug | last post by:
Hello Everyone, I'm in the middle of what has turned into a very strange project. I am desperate and could use some help. Here are the circumstances: - The company I'm working for uses Excel '02. - I was initially asked to do this as an Access DB, but... - Data comes from a web-based report generator into an Excel workbook, so why go with Access, especially when no one in the office knows how to use it... - Generated workbook has a...
1
8780
by: Ally | last post by:
Hi all, I’m looking to plot charts in Excel from python. After some Googling I’ve found the following code: def plot(x, y, xAxisLog=False, yAxisLog=False): # acquire application object, which may start application application = Dispatch("Excel.Application") # create new file ('Workbook' in Excel-vocabulary)
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.