How to change MsoLineJoinStyle with VBA? - 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.

Related

Acrobat AddNewAnnot SetContents fails

I want to add a new FreeText comment to a PDF file with vba.
Public Sub AddAnnot(Page As Object, Text As String)
Dim Rect As Object, Annot As Object
Set Rect = CreateObject("AcroExch.Rect")
Dim Space As Integer, Height As Integer
Space = 0
Height = 15
With Rect
.bottom = Space
.Left = Space
.Right = Page.GetSize.x - Space
.Top = Space + Height
End With
Set Annot = Page.AddNewAnnot(0, "FreeText", Rect)
With Annot
.SetTitle Text
.SetContents (Text)
.SetColor RGB(255, 255, 0)
.SetRect Rect
End With
End Sub
So this code worked with older versions of Acrobat, but now in Acrobat DC, it always fails at the line .SetContents (Text) with the simple error, that the method has failed. It doesnt matter, which pdf-file it is, it always fails.
What am i doing wrong?
Thanks in advance
For everyone who was desperately searching for a solution to this, but didn't find one: Before the whole procedure of adding Annots, open the document as an AVDoc, too. You don't have to use it, just opened and it works, even when you instantly hide it.

Add a gradient to a shape/line

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.)

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-

Excel VBA: Positioning and Alignment of Shapes

I am trying to make a printable report from excel sheet with some shapes such as charts and pictures. I am able to put the charts on the sheet using the below code:
oSheetReport.Range("A51").Select()
Dim oChart1 As Excel.Shape
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlLine
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
oSheetReport.Range("A70").Select()
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlColumnStacked
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
oSheetReport.Range("A100").Select()
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlColumnStacked100
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
But positioning and alignment is failing which is making my reports look ugly. Any better way of achieving this?
To add, position and align in one step you can use the following:
Set oChart1 = ActiveSheet.ChartObjects.Add _
(Left:=250, Width:=375, Top:=75, Height:=225)
Left is the left alignment and Top is the top alignment. Width and Height - well, you can figure that out!
More info at http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html

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