Add a gradient to a shape/line - vba

I am attempting to add a gradient to a line shape in Excel using VBA. This feature is available in the Line Color section under the Format Shape option. Despite this feature existing under the Format Shape option, I am unable to reproduce the functionality in VBA. My code is:
With ActiveSheet.Shapes("Straight Connector 4")
.Line.ForeColor.RGB = RGB(193, 193, 193)
.Line.Transparency = 0.25
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = 24
.Line.BackColor.SchemeColor = 34
.Line.GradientStops.Insert RGB(255, 0, 0), 0.25 ' Creates error
.Line.Gradient.ColorStops.Add (1) ' Creates error
End With
I know you can easily add a gradient to the shape fill but all search results are returning nothing when wanting to add a gradient to a shape line. Any ideas are more than welcome.

As far as I know, it is not possible. You can set a gradient for a shape's fill through VBA, but you can't do it for a line.
You can either create a thin shape with gradient fill and no border, or you will have to use something outside VBA. (Eg. VB.NET + OpenXLM SDK.)

Related

How to change MsoLineJoinStyle with VBA?

I'm tring to create a rectangle in word 2016, and want to change the join style with VBA:
With ActiveDocument.Shapes.AddShape(msoShapeRectangle, left, top, width, height)
.Line.Weight = 11
.Line.ForeColor.RGB = RGB(32, 56, 100)
.Line.Style = msoLineSingle
'.Line.JoinStyle = msoLineJoinBevel
End With
It seems that the Line object doesn't have JoinStyle property, so how could I change it ?
I've checked the document https://learn.microsoft.com/en-us/office/vba/api/word.lineformat and I've also googled a lot, but didn't find the answer.
I want to change the JoinStyle by VBA, any help? Thanks.

Align a text frame when creating a ppt from access vba

I'm trying to align a text frame when creating a ppt from access. Alignment control is available from excel vba but I'm struggling to find this in access.
Here is an example of the creation of a textbox in powerpoint from access vba. I have control of the font size and such but I cannot locate the alignment for the textbox.
' Program data
Dim tb_ProgramData As Shape
Set tb_ProgramData = pptCurrentSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=68.399, Top:=51.12, Width:=187.2, Height:=18.72)
tb_ProgramData.TextFrame.TextRange.Text = rs.Fields(27) + " Program: " + rs.Fields(29)
tb_ProgramData.TextFrame.TextRange.Font.Size = 9
tb_ProgramData.TextFrame.TextRange.Font.Bold = msoTrue
The only thing close is a paragraph alignment but it has no effect...
tb_Title.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
Any help would be appreciated... regards,
Good grief.. I found it under the text effects.
tb_SystemClass.TextEffect.Alignment = msoTextEffectAlignmentRight
and if you wish to select the textbox from the list of shapes then...
pptCurrentSlide.Shapes.Range("tb_SystemClass").TextEffect.Alignment = msoTextEffectAlignmentRight

Possible to apply a Shadow to an entire Group with VBA (but not to GroupItems)?

I'm working on a PowerPoint VBA script to apply some default styles to selected objects, and I'm running into some problems with grouped objects. Essentially, if I apply ShadowFormat adjustments to a Shape group, the shadow is applied to the items within the group rather than to the group itself.
In the example below, the white box, blue box, and blue circle are all grouped. Using the GUI to set a shadow on the group results in just the bounding shape to receive the shadow (i.e., the blue objects don't get a shadow). When applying the shadow via a VB script, however, the shadow is applied to all three objects individually, which is not the desired behavior. Inspecting the group with the Format Palette verifies that no shadow is applied to the group directly.
Image: Shadows on groups problem (Sorry for the link, I don't have enough rep to post images yet...)
Here's a code snippet. In this example, the Group in question is the first item on the slide:
Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes(1).Shadow
.Visible = True
.ForeColor.RGB = RGB(0, 0, 0)
.Blur = 12
.Transparency = 0.4
.OffsetX = 0
.OffsetY = 3
.Obscured = msoTrue
End With
I expect the shadow to only be applied to the group, as it is when you use the GUI to apply a shadow to a group. Instead, all of the group's sub-shapes have their shadows set, and the group itself does not receive a shadow.
Shadow is a property of a shape. A group is not a shape. So shadows can only be applied to the members of the group, not the group itself.
To get this effect, copy all shapes, make an array out of them, merge them using the MergeShapes method, send the merged shape to the back and apply a shadow to it. Here's how to use MergeShapes, thanks to Shyam Pillai for this:
Dim shp1 As Shape
Dim shp2 As Shape
Set shp1 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeOval, 100, 100, 50, 50)
Set shp2 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapePie, 100, 100, 50, 50)
Call ActiveWindow.Selection.SlideRange(1).Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition)).MergeShapes(msoMergeCombine)

Microsoft.Office.Interop.Excel Line Chart Color And Bar Chart Color Alpha

I am using the following code to format properties of a chart created by Microsoft.Office.Interop.Excel.
xlChart.SeriesCollection(1).ChartType = XlChartType.xlColumnClustered
xlChart.SeriesCollection(2).ChartType = XlChartType.xlLine
xlChart.SeriesCollection(1).Interior.Color = Color.FromArgb(255, Color.DeepSkyBlue)
xlChart.SeriesCollection(2).Interior.Color = Color.FromArgb(255, Color.DarkOrange)
I have two problems. For the xlColumnClustered chart, the color is fine but the Alpha value does not have any affect (whether being 0 or 126 or 255). For the xlLine even the color doesn't get set. I know probably for xlLine I shouldn't use .Interior.Color but I don't know what I am supposed to use. Any help will be appreciated.
I don't think you can use a transparent color directly. What you can do is set the transparency parameter of the series like this:
Chart.SeriesCollection(1).Format.Fill.Transparency = 0.5
For line you should use:
Chart.SeriesCollection(1).Format.Line.Forecolor.RGB = RGB(255, 0, 0)
I wrote a blog post about how to find out which objects and properties should you use to achieve your result. It seems it might help you find with other difficulties in locating the right objects to use-

Vba - Set transparent color or direct hex value of label backcolor?

I want to insert a label into a PowerPoint presentation. But I don't want any background on there, or, have the background color be the same as the what is underneath.
I've found that 082F68 is the hex code I want. The RGB code is: 8, 47, 104
This color is supposed to be bluish, but when I insert it, it just gets brown.
I really don't want that. I also tried setting label.backcolor to Color.Transparent. But that isn't recognized. Neither is System.Drawing.Color.Transparent either. It just says it needs an object reference.
But really, isn't it possible to use direct hex values for label backgrounds?
(super late response, but in case others have this issue)
This will create a label on slide 1 in the upper-left hand corner. On my system, I get the bluish background color you are talking about.
ActivePresentation.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=0, Top:=0, Width:=50, Height:=50).name = "TestLabel"
Dim sh As Shape
Set sh = ActivePresentation.Slides(1).Shapes("TestLabel")
sh.TextFrame.TextRange.Text = "Hello"
sh.Fill.BackColor.RGB = RGB(8, 47, 104)
You can also set the fill transparency to 100% (fill will be see-through):
sh.Fill.Transparency = 1#
I'm not sure what you're using as a "placeholder", but any Shape object will have an ID:
MsgBox "Label ID = " + CStr(sh.Id)
but it is probably easier to refer to it by name as I do above. The ID is a numerical value and isn't the same as the shape index, making it harder to reference the shape by its ID.
Above I programmatically assign the name, but you can also name the shape yourself: Home -> Arrange -> Selection Pane. In the selection pane you can click on the names of all the shapes on the slide to edit them. You can now refer to these shape names in code.
Try *.BackgroundColor = -1 'Transparent