Powerpoint Modify Chart Legend width - vb.net

I am using VB.net to create charts in Powerpoint and have a small problem: The customer wants the legend bigger than the original design. Is this possible with Interop?
I have a basically this structure:
Dim TargetChartas Microsoft.Office.Interop.PowerPoint.Chart
TargetChart.HasLegend=true
With TargetChart.Legend
.Position = Microsoft.Office.Interop.PowerPoint.XlLegendPosition.xlLegendPositionTop
.Format.TextFrame2.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue
.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue
End Width
But I am unable to find a width property - like any normal shape posess.
Do you have any Idea how to do this?
I added the excel tag because the charts are basically excel charts.
Argh: I need more tea. I just realized that Office 2010 HAS a width property, whereas 2007 does not. So I just have to check the powerpoint version... oh joy...

Powerpoint 2010 and later has a width property, so it works there. The width and left properties are somewhat weird, they seem to be relative to the chart. So expect some experimentation.
If you have to support Office 2007 you can check the application version: Chart.application.version 14.0 is Office 2010. I converted it to a number and check if it is greater than 14.

Related

How to change data label width in an Excel chart with VBA?

I want to change a label width in Excel chart by VBA code:
set lbl = SERIES1. points(1).datalabel
msgbox lbl.width 'this is working
lbl.width = 40 ' compile error: wrong number of arguments or invalid property assignment
I can get the label width but cannot change it. What am I doing wrong?
AFAIK, the width of a chart data point label is not configurable. Even though the width can be retrieved with VBA, it's not possible to set or change it with a VBA command or property.
According to the documentation, the DataLabels.Width property is read only.
Returns the width, in points, of the object. Read-only.
Source
Excel chart labels remain stubbornly uncooperative and resist formatting attempts, be it with VBA or with the UI.
That's (unfortunately) just how Excel works.
Don't shoot the messenger.
If you want to make a difference, consider raising an idea at excel.uservoice.com
This works in Excel 2016, you'll just need to adjust the series collection and point numbers to fit your needs. ActiveChart.FullSeriesCollection(1).Points(1).DataLabel.Width = 363.314.

Change Axis Labels font size in PowerPoint 2010 VBA

Hi I am using PowerPoint 2010 and I am trying to change font size of Axis labels in a chart using VBA but I am getting the following error.
"Method 'TextFram2' of object 'ChartFormat' failed"
The code I am using to change the font is below.
.Axes(xlCategory).Format.TextFrame2.TextRange.Font.Size = 10
This codes works fine in Microsoft Excel but does not work in PowerPoint.
You can do it like this:
.Axes(xlCategory).TickLabels.Font.Size = 12

How can I add a macro to a Word 2010 or PowerPoint 2010 chart?

In PowerPoint 2010 or Word 2010, when I choose Insert -> Chart, it creates a new chart with an Excel worksheet for the data.
If I add a macro to the Excel worksheet, this seems to be discarded when I close the worksheet and re-open it.
However, it is possible to have a chart with macros, because I also have some Word documents & PowerPoint presentations that I created in Office 2003, which had embedded Excel charts with macros. When I converted those to Office 2010, they look just like "normal" Office 2010 charts, but the macros are preserved.
It looks to me like the embedded chart that gets created when you choose Insert -> Chart is in the "pptx" format rather than the "pptm" format, and so macros are not saved.
(If I query ActiveWorkbook.FileFormat, I get "51", which is "Open Xml Spreadsheet"; this is indeed "pptx", as opposed to "Open Xml Spreadsheet with Macros", which is "52").
How can I insert a chart with the "pptm" behavior? Or change the behavior of an existing chart?
NOTE: I do not want to insert a chart "object", since this means that the chart is not editable within the host application (it merely inserts an Excel chart that you need to "open" in order to edit it).
Let me give you a head start... I can achieve what I want by the following method:
Create a new document in Word (or PowerPoint).
Save the document as a 97-2003 document (which forces it into compatibility mode).
Insert a chart using Insert->Object->Microsoft Excel Chart. This embeds an old-style Excel chart.
Open the embedded chart by right-click->Open, and add a macro.
Close the chart, then choose File->Info and use the Compatibility Mode "Convert" button to convert the document into an Office 2010 document.
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
Now, does anyone have a simpler way?
In my opinion you could achieve what you need in the following way:
(unfortunately, I can't present it with pictures and exact English commands as I'm using local-not English-version of Office)
Choose Insert >> Object >> Object...
In Object window take first page (like Create new)
Search for Microsoft Excel Chart (or something similar) and press
OK
You will get Workbook with two sheets as presented on the picture
below
(there are chart editing feature available on the Ribbon)
Press Alt+F11 while you are in Chart edition like presented in the
picture above. You will get IDE for Excel opened where you will find
appropriate workbook.
Add new module and macro there
Now you could exit chart edition in Word and save document as *.docm
After you will reopen it, go to Chart Edition (double click) >> Alt+F11 >> you will
find you macro there saved within the workbook with *docm extension.
Now that the bounty has passed (with no better answers), I'll add the partial answer from my question, in order to be able to close the question.
Create a new document in Word (or PowerPoint).
Save the document as
a 97-2003 document (which forces it into compatibility mode).
Insert
a chart using Insert->Object->Microsoft Excel Chart. This embeds an
old-style Excel chart.
Open the embedded chart by right-click->Open,
and add a macro.
Close the chart, then choose File->Info and use the
Compatibility Mode "Convert" button to convert the document into an
Office 2010 document.
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
I'm still interested in being able to do this more directly...
The issue is with how the charts data is held within the application. Converting and originating are two different processes. Your data series is basically an array not an excel sheet. It just uses excel to display the data to you to edit. You need to keep your code in the module for powerpoint/word and access the chart via the shapes object if you do not want to embed a excel sheet.
Sub GetChartName()
Dim sSlide As Slide
Dim cChart As Chart
Dim sShape As Shape
Set sSlide = PowerPoint.ActivePresentation.Slides(1)
For Each sShape In sSlide.Shapes
If sShape.HasChart Then
Set cChart = sShape.Chart
MsgBox cChart.Name
Set cChart = Nothing
End If
Next
Set sSlide = Nothing
End Sub

Not able to bring in front the frames in Word 2010

I have similar doucment in Word 2003 and Word 2010 and all the styles been imported to Word 2010 document.
In Word 2003 I have a frame and document with two columns and a seperator line as shown below. The frame is on top of the line.
Similar to Word 2010 I got a frame on a document with two columns with a seperator but the seperator line is visible in the frame.
How can I make the Word 2010 frame similar to Word 2003 frame? This is a silly question but it is really annoying for me and I have this problem for the last 3 months open.
I would really appreciate your help on this.
The shading fill color was set to white and it worked after setting shading fill color to white in Word 2010 for the frame.
Closing my own question

How to use VBA in Word 2007 to update PictureStyles in one assignment?

I am trying to help a co-worker with some Word 2007 picture formatting. I would like to be able to update the Border style, drop-shadow, etc. by assigning the pictures one of the named styles that you can select from the Picture Formatting tab in the ribbon. The style I am trying to use is called 'Simple Frame, Black'. Unfortunately, I haven't found any documentation in the Object Model Reference about using these styles for InlineShapes.
I tried recording a macro, both by using the mouse to go through the steps, and only using the keyboard to do what I want, but none of the picture style assignment steps show up in the resulting vba module.
I found a question that is similar on egghead here
From this, it sounds as though maybe this functionality isn't exposed in the Object model. I'm wondering if anyone has found a way to do this, and if not, what the best way to get around it would be.
Thanks,
Spencer
As far as I can tell there isn't a way to directly set the named picture styles from VBA. It is a little time consuming but my suggestion would be to insert two pictures into a word document, apply the formatting to one of them, then examine both objects in the VBE Watch window.
Based on my experience with Word 2010, the things to pay attention to are: Borders, Fill, Glow, PictureFormat, Reflection, Shadow, & SoftEdge.
In Word 2010 to change a picture without formatting to have the same formatting as the 'Simple Frame, Black' style apply the following changes:
With ThisDocument.InlineShapes(1)
.Borders.OutsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth300pt
With .Shadow
.Blur = 4
.OffsetX = 2.12132
.OffsetY = 2.12132
.Style = msoShadowStyleOuterShadow
.Transparency = 0.57
.Visible = msoTrue
End With
End With
The Shadow Blur and Offsets are minor changes you can't really see.