Excel 2007 chart line width + axis labelling with VBA

Folks,

I'm creating a line-style chart with VBA in Excel 2007 and an
attempting to control just two things:

1) The line weight (2 points) and
2) The text direction of the X-axis labels (they're inclined, I want
them vertical).

Now I can indeed achieve both these settings through the UI (Format
Data Series/Line Style/Width and Format Axis/Alignment/Text direction/
Rotate through 270 degrees respectively) and naturally I thought that
the macro recorder would help but alas, all I got was

....
    ActiveSheet.ChartObjects("Chart 19").Activate
    ActiveChart.Axes(xlCategory).Select

I've gone through the online help and tried this and that but without
success.

Any ideas?  TIA.
0
8/22/2009 12:08:38 AM
excel.charting 18370 articles. 0 followers. Follow

6 Replies
420 Views

Similar Articles

[PageSpeed] 24

Hi,

Try,

activechart.SeriesCollection(1).format.line.weight=2
activechart.Axes(xlcategory,xlPrimary).ticklabels.Orientation = 
xlTickLabelOrientationVertical

Cheers
Andy

HB wrote:
> Folks,
> 
> I'm creating a line-style chart with VBA in Excel 2007 and an
> attempting to control just two things:
> 
> 1) The line weight (2 points) and
> 2) The text direction of the X-axis labels (they're inclined, I want
> them vertical).
> 
> Now I can indeed achieve both these settings through the UI (Format
> Data Series/Line Style/Width and Format Axis/Alignment/Text direction/
> Rotate through 270 degrees respectively) and naturally I thought that
> the macro recorder would help but alas, all I got was
> 
> ...
>     ActiveSheet.ChartObjects("Chart 19").Activate
>     ActiveChart.Axes(xlCategory).Select
> 
> I've gone through the online help and tried this and that but without
> success.
> 
> Any ideas?  TIA.

-- 

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
0
andy9699 (3616)
8/22/2009 9:50:32 AM
Sadly the macro recorder does not seem to record actions to charts and 
shapes in Excel 2007. Maybe this will get you started, note generally no 
need to select anything.

Sub test()
Dim cht As Chart
Dim sr As Series
Dim ax As Axis

    Set cht = ActiveSheet.ChartObjects("Chart 1").Chart ' << change name to 
suit

    Set ax = cht.Axes(xlCategory)

    ax.TickLabels.Orientation = xlTickLabelOrientationVertical

    For Each sr In cht.SeriesCollection
        sr.Format.Line.Weight = 2
    Next

End Sub


If you fully declare your object variables, as above, you'll find the 
Intellisense helps a lot in working things out.

Regards,
Peter T


"HB" <HowardBryden@aapt.net.au> wrote in message 
news:6ea1fb1c-74a6-44f7-9ed7-447ac2d3a43c@l35g2000pra.googlegroups.com...
> Folks,
>
> I'm creating a line-style chart with VBA in Excel 2007 and an
> attempting to control just two things:
>
> 1) The line weight (2 points) and
> 2) The text direction of the X-axis labels (they're inclined, I want
> them vertical).
>
> Now I can indeed achieve both these settings through the UI (Format
> Data Series/Line Style/Width and Format Axis/Alignment/Text direction/
> Rotate through 270 degrees respectively) and naturally I thought that
> the macro recorder would help but alas, all I got was
>
> ...
>    ActiveSheet.ChartObjects("Chart 19").Activate
>    ActiveChart.Axes(xlCategory).Select
>
> I've gone through the online help and tried this and that but without
> success.
>
> Any ideas?  TIA. 


0
Peter
8/22/2009 9:52:06 AM
On Aug 22, 7:52=A0pm, "Peter T" <peter_t@discussions> wrote:
> Sadly the macro recorder does not seem to record actions to charts and
> shapes in Excel 2007. Maybe this will get you started, note generally no
> need to select anything.
>
> Sub test()
> Dim cht As Chart
> Dim sr As Series
> Dim ax As Axis
>
> =A0 =A0 Set cht =3D ActiveSheet.ChartObjects("Chart 1").Chart ' << change=
 name to
> suit
>
> =A0 =A0 Set ax =3D cht.Axes(xlCategory)
>
> =A0 =A0 ax.TickLabels.Orientation =3D xlTickLabelOrientationVertical
>
> =A0 =A0 For Each sr In cht.SeriesCollection
> =A0 =A0 =A0 =A0 sr.Format.Line.Weight =3D 2
> =A0 =A0 Next
>
> End Sub
>
> If you fully declare your object variables, as above, you'll find the
> Intellisense helps a lot in working things out.
>
> Regards,
> Peter T
>
> "HB" <HowardBry...@aapt.net.au> wrote in message
>
> news:6ea1fb1c-74a6-44f7-9ed7-447ac2d3a43c@l35g2000pra.googlegroups.com...
>
>
>
> > Folks,
>
> > I'm creating a line-style chart with VBA in Excel 2007 and an
> > attempting to control just two things:
>
> > 1) The line weight (2 points) and
> > 2) The text direction of the X-axis labels (they're inclined, I want
> > them vertical).
>
> > Now I can indeed achieve both these settings through the UI (Format
> > Data Series/Line Style/Width and Format Axis/Alignment/Text direction/
> > Rotate through 270 degrees respectively) and naturally I thought that
> > the macro recorder would help but alas, all I got was
>
> > ...
> > =A0 =A0ActiveSheet.ChartObjects("Chart 19").Activate
> > =A0 =A0ActiveChart.Axes(xlCategory).Select
>
> > I've gone through the online help and tried this and that but without
> > success.
>
> > Any ideas? =A0TIA.

0
8/23/2009 5:47:02 AM
On Aug 22, 7:52=A0pm, "Peter T" <peter_t@discussions> wrote:
> Sadly the macro recorder does not seem to record actions to charts and
> shapes in Excel 2007. Maybe this will get you started, note generally no
> need to select anything.
>
> Sub test()
> Dim cht As Chart
> Dim sr As Series
> Dim ax As Axis
>
> =A0 =A0 Set cht =3D ActiveSheet.ChartObjects("Chart 1").Chart ' << change=
 name to
> suit
>
> =A0 =A0 Set ax =3D cht.Axes(xlCategory)
>
> =A0 =A0 ax.TickLabels.Orientation =3D xlTickLabelOrientationVertical
>
> =A0 =A0 For Each sr In cht.SeriesCollection
> =A0 =A0 =A0 =A0 sr.Format.Line.Weight =3D 2
> =A0 =A0 Next
>
> End Sub
>
> If you fully declare your object variables, as above, you'll find the
> Intellisense helps a lot in working things out.
>
> Regards,
> Peter T
>
> "HB" <HowardBry...@aapt.net.au> wrote in message
>
> news:6ea1fb1c-74a6-44f7-9ed7-447ac2d3a43c@l35g2000pra.googlegroups.com...
>
>
>
> > Folks,
>
> > I'm creating a line-style chart with VBA in Excel 2007 and an
> > attempting to control just two things:
>
> > 1) The line weight (2 points) and
> > 2) The text direction of the X-axis labels (they're inclined, I want
> > them vertical).
>
> > Now I can indeed achieve both these settings through the UI (Format
> > Data Series/Line Style/Width and Format Axis/Alignment/Text direction/
> > Rotate through 270 degrees respectively) and naturally I thought that
> > the macro recorder would help but alas, all I got was
>
> > ...
> > =A0 =A0ActiveSheet.ChartObjects("Chart 19").Activate
> > =A0 =A0ActiveChart.Axes(xlCategory).Select
>
> > I've gone through the online help and tried this and that but without
> > success.
>
> > Any ideas? =A0TIA.

Andy & Peter,

Thanks, I eventually hit upon TickLabels.Orientation (despite the
Byzantine labyrinth that is the Excel online help); instead of Format
I eventually came upon the Border property which seemed to work also:

With .SeriesCollection(1)
....
     .Border.Weight =3D n
End With

It seems the online help (along the Object Browser and Macro Recorder)
bear the hallmarks of a project rushed out the door with quite a few
gaps and rough edges.

Anyway thanks again guys.
0
8/23/2009 5:55:29 AM
That's the method for formatting the border (ie line) weight in 
Excel97-2003, and works in 2007 for compatibility. The .Weight property can 
accept any one of four constants, 1, 2, -4138, or 4, also named as 
xlHairline, xlThin, xlMedium & xlThick respectively.

Providing your value for 'n' is one of these constants your code will work. 
But don't try say 5 (you can apply 3 but it will read back as -4138). For 
2007 better to use the method Andy and I suggested.

Regards,
Peter T


"HB" <HowardBryden@aapt.net.au> wrote in message 
news:f1adf471-21b9-45c0-914f-
I eventually came upon the Border property which seemed to work also:

With .SeriesCollection(1)...
     .Border.Weight = n
End With



0
Peter
8/23/2009 9:32:25 AM
On Aug 23, 7:32=A0pm, "Peter T" <peter_t@discussions> wrote:
> That's the method for formatting the border (ie line) weight in
> Excel97-2003, and works in 2007 for compatibility. The .Weight property c=
an
> accept any one of four constants, 1, 2, -4138, or 4, also named as
> xlHairline, xlThin, xlMedium & xlThick respectively.
>
> Providing your value for 'n' is one of these constants your code will wor=
k.
> But don't try say 5 (you can apply 3 but it will read back as -4138). For
> 2007 better to use the method Andy and I suggested.
>
> Regards,
> Peter T


Thanks, that's indeed what I've done.
0
8/25/2009 12:01:12 AM
Reply:

Similar Artilces:

Rollup 2 and Office 2007
I already have Roll Up 1 and the Office 2007 compatibility patch installed. If I now install roll up 2 will I have to reinstall the office 2007 compatibility? yes -- Regards, MS CRM Certified Professional http://microsoftcrm3.blogspot.com Chat with me on MSN / Gmail / Skype : ID Is :.. mscrmexpert@gmail.com "LLoyd" wrote: > I already have Roll Up 1 and the Office 2007 compatibility patch installed. > If I now install roll up 2 will I have to reinstall the office 2007 > compatibility? ...

Excel not Access
I have designed an Access database that holds records relating to my stores audit results going back for about 5 years plus a load more information relating to these stores. This was used to produe a pack once a month, however a change in senior management means that I have got to shelve this and prodce a similar pack in Excel. The idea would be that the user could select a month or a 12 mnth date range that would produce data that could then be used to populate a number of excel templates that have been designed. Having not used excel for years I would be grateful for any suggestion...

How to keep format when importing Excel into SQL.
Can anybody help me please? When I import Excel file into SQL, a field that formated as 0000000000 (custom), loosing leading zeros. I tried to change data type in SQL after importing. No luck. I appretiate any help. See if using IMEX=1 helps: http://pratchev.blogspot.com/2007/10/importing-excel-data-into-sql-server.html -- Plamen Ratchev http://www.SQLStudio.com Plamen, I tried this, but got an error: "The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered." Thank you very much for looking into this. "Plamen Ratchev" wr...

Auto-format in Microsoft Excel.
Each time i try to enter a number range, for example, 8- 10, in Excel, it constantly re-formats it to a date. If I change the formatting to "General" it turns it into a random number, usually 38209. I would like to turn off ALL auto-formatting, but that's probably asking too much. How do I disable this frustrating feature? thanks. Hi Paul When you enter "8-10" in a cell, that's not strictly a number but Excel thinks you mean a date so converts it as such. A date is a number and in your example the number 38209 represents August 10 2004 which is not a ra...

how do I automatically update a text box in a chart?
Hi, You can link the textbox to a cell. When you update the cell the textbox should reflect this. Select the textbox border and then in the formula bar enter the complete cell reference, for example, =Sheet1!A1 Cheers Andy Kath wrote: -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info ...

Excel 2007
When I select cells to copy as a picture in Excel 2007, the resolution is terrible. Text and objects with shadow's are very blotchy when pasting the picture. How do you change the resolution of a 'Copy Picture'? ...

Using part of a cell in a chart title
I have a chart which should get a title. However, this should be partly be used from a cell e.g. "counted with 5%" 5% should be taken from the cell and used in the title. Is this possible? Hi, Yes it's possible but all of the chart title needs to be in the cell. So you may need to use a helper cell and concatenate text and value. http://www.andypope.info/tips/tip001.htm Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Nicole" <Nicole@discussions.microsoft.com> wrote in message news:5CB7A971-AA7F-4C34-BB42-7DC283AA2958@micro...

Input Excel 'Password to Open' through control in access form
Hi All, We know,Excel has prompt password to open it files. Is it possible to create a code that can supplies the excel prompt password?.So that when we open the excel file through our access control in a form, the excel files can be opened automatically.But when the excel files opened from its default icon,it will prompt a password first. ...

How To Copy MS Word mailing labels into Excel
I have a word doc that I want to put into Excel. I want to add some more fields to the names and addresses. Is this simple or do I have to learn how to program? Michael Rodriguez City of Grand Prairie Michael, have you tried to copy and paste the data into excel? -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Michael Rodriguez" <mrodrigu@gptx.org> wrote in messa...

How do I use traffic lights in excel
I am wanting to use traffic lights in excel that change colour based on the result of a variance cell, ie if the result of the cell is 10 make the traffic light green, if it is 20 make the traffic light amber, if the result is 30 make the traffic light red. How do I do this? Shorty Format>Conditional Formatting>Cell Value is: Note: you can add up to 3 conditions(4 if you count default) Gord Dibben Excel MVP On Wed, 22 Dec 2004 16:35:03 -0800, Shorty <Shorty@discussions.microsoft.com> wrote: >I am wanting to use traffic lights in excel that change colour based on the &g...

Grammar check not working
Hello, I am using Word 2007 and have a problem with grammar and punctuation errors. I deliberately put two spaces between words, do not put space after a comma, write long sentences and finish a sentence without a verb but the green underline never appears. The spell check is functioning properly, no problem with that. In Word Options > Proofing, "Mark grammar errors as you type" is selected. I changed that selection and tried again but it still did not work. I used different languages as default language but no change. I would be grateful if someone could come...

How to change font size on formula bar in Excell 2007
I don't find Tools>Options>General (as suggested in other post answers) in Excel 2007. On the Office button there is an Excel Options but it doesn't provide a method of changing font size on the office but. My font is so small I can barely see it. Office button>ExcelOptions>Popular tab>in the "When creating new workbooks" section, choose font and font size -- Kind regards, Niek Otten Microsoft MVP - Excel "jimwillie" <jimwillie@discussions.microsoft.com> wrote in message news:588AAC05-0F52-404E-AA01-128E70E02D0B@microso...

Opening Excel Workbooks
I'm running into an issue where if I click on an Excel file through My Documents, it doesn't automatically bring it up. I get the toolbar but the actual spreadsheet doesn't appear on the screen. I have to click on the taskbar to get it to pop up. If I already have Excel active and I open a file through Excel, this doesn't happen. Any ideas? Here is a similar thread: http://www.excelforum.com/showthread.php?s=&threadid=237195 Rolli -- Message posted from http://www.ExcelForum.com Hi, Take a look at Tools-Options-General tab- uncheck ignore other application...

Radar chart in Access 2007 report
Can you add a Radar chart to an access 2207 report? ...

Chart template?
I am working with a chart, created from a pivot table. The chart has the various [drop down] fields available for selecting different values for the chart to show. I have formatted the chart with specific settings, fonts, colors, etc., but everytime I use one of the dropdowns, the formatting goes back to the default. I have looked for a place to save as a template, or defaults without luck. Thanks for any help you can provide! Alan ...

Unexpected error message on closing an Excel file
Suddenly I am getting the following message when I try to close a workbook: "Your formula contains an invalid external reference to a worksheet. Verify that the path, workbook, and range name or cell reference are correct, and try again" The mysterious thing is that it does not happen consistently and that, after I click OK after the above message, I can still save the file. What might be the cause of this error message and can the "invalid reference" be tracked down using one of the utility add-ins such as J. Walkenbach's PUP? If it only happens when you close ...

help with simple maths in excel
I want to do a simple arithmatic excercise in excel for my grand daughter. It is stuff like 2+2 =4 Smart me has hit a problem at the first hurdle... I need to put 2 in one cell the + in another cell and then 2 in another = in another and then she puts the answer in the next one. So the above would have 4 cells completed and she would put the answer in the 5th one. When I use the + or = sign in a cell of its own it (excel) thinks I am doing an equation, is there a way around this? I will work on the answer like if she gets it correct or wrong how I will do that...a sound or som...

[b]Can I download Excel data to a MS Access database?[/b]
I've built an Excel 2002 form that I want our internal customers to access from our intranet, and use. Once completed, they will send it to us as an e-mail attachment. I'd like to be able to open it, and somehow download the data from the form into an MS Access 2002 database I've built (so that we don't have to rekey it into the database). Is this possible or even feasible? Any and all help is appreciated. Thanks. :D --------- Message sent via www.excelforums.com Hi in Access check 'File - Import External data' -- Regards Frank Kabel Frankfurt, Germany "...

Excel Problem
I have a 23.8 meg excel 2000 spreadsheet set for manual calculation saved to my local hard drive. Every time I try to open it, it takes forver and sometimes never opens but I do not get any error messages, let me just tell you that I am running a P4, 1 GB memory, Office 2K with SP3, and nothing else running when I try to open it. As I said it is set for manual calculation, and it is cleared to not auto calculate when opening or closing. Any idea's as to why this is happening? -- Todd I don't know why you're having this problem but I would like to point something out for w...

Excel DNS query
Hello, Is there a way for an Excel function to query a DNS server? Thanks. Soundy Not that I know of, but you can turn on the macro recorder, use 'get external data' and tailor the resulting code into a user function of your own. E.g. I've used this to create a button to get MS-Access data from a query that has the same name as the sheet (tab) name. It saves me a lot of copy-paste actions. Bas Hartkamp <soundy@gmail.com> schreef in bericht news:1151940450.029823.127570@j8g2000cwa.googlegroups.com... > Hello, > > Is there a way for an Excel function ...

Embedded Chart Versus Chart
I've created a class module to capture a Shift+Click on a pivot chart, which then opens the data associated with that point. It works great on pivot charts on their own sheet, but when I use the same code on an embedded chart, it fails (error code -2147417848). Everything seems to work fine, it derives the same row and column values as needed, but the ShowDetail property is unavailable in the embedded charts. Anyone have any insight? james Igoe || james.igoe@gmail.com || http://code.comparative-advantage.com I eventually solved my problem, simply using "On Error Resume Next&...

Exchange 2007 across account search
Does Exchange 2007 has an option to search all users mail for keywords? That all SBS workgroup users can search for messages to/from all other users. Is there any advanced indexing system to speed up search results? Thanks! On Tue, 26 Jan 2010 14:22:12 +0200, "Ronald" <2omikk@gmail.com> wrote: >Does Exchange 2007 has an option to search all users mail for keywords? >That all SBS workgroup users can search for messages to/from all other >users. >Is there any advanced indexing system to speed up search results? > >Thanks! > Bunch of ...

Calculating age in a label or text box on a form
Hello All, I have a text box for birthdate for a user to enter the birthdate and I want to the age for the user to be automatically calcuated and displayed in another label called "Age." What formula can I use? Missy ...

Please Help w/ Large Excel File
Hello everyone. I have this Excel file that has drawing text box objects in the document. When I delete a text box the attributes still are present, but just not showing. It is continually growing my file size. When I export the document to HTML after deleting all the text box drawing objects and saving the file, the text box objects still show as vtextbox elements in this file. I tried to reproduce this with a new Excel workbook but could not. I would be greatful if anyone can figure this out, as I have a lot of documents to re-create if there is no solution. Thank you. exce...

How can I set an alarm Excel?
I would like to set an audible alarm in Excel based on a cell value. Try this in the worksheet VBA editor. If the value of A5 is greater than 50 you get a beep. Private Sub Worksheet_Change(ByVal Target As Range) Dim frequency As Long Dim duration As Long If Target <> Range("A5") Then Exit Sub If Target.Value > 50 Then frequency = 4160 duration = 1500 Call Beep(frequency, duration) End If End Sub HTH Regards, Howard "Annell" <Annell@discussions.microsoft.com> wrote in message news:EFE8AA18-3F14-4A92-941D-053922417AB2@mic...