How to maintain the size of fonts in anchored MSGraph Chart object - vba

I have a anchored MSGraph Chart object on my form to stretch left and bottom. It stretches well but the fonts also stretch. How do I maintain the same font size for all the Data labels but still be able to view the graph in full size on stretched or zoomed mode? My aim is to keep font sizes for all Data labels and Axis to 11pt. The original font size for the Data Labels and Axis is 8pt
Edit:
I have notice that when I select the Zoom or Stretch features in the Chart's properties sheet, the chart stretches and the so does the fonts. This does not happen if I select Clip
Is it possible to make the chart stretch whilst maintaining the font sizes to 11pt? I am asking this because when I looked at the chart on a 4:3 screen today, some fonts were barely visible. Please see the image of my current graph and together with its properties settings below:

I have inserted a Stacked Layout with two cells onto the the form, then inserted the chart object in the first cell and left the second cell empty.
A good thing is that an empty cell can be anchored to Strech when the form resizes to suit the screen's aspect ratio.
I then adjusted the height of the blank cell and anchored both the object and the blank cell to Sctrech Down and Across.
On the chart properties, the chart Size Mode must be set to Strecth
Then used the below code on the form open event:
Note: This code requires the use of Microsoft Graph Object Library which should be added using the Tools -> References feature on the code editor.
I am using Microsoft Graph 16.0 Object Library.
I shall be exploring how to use latebinding inorder to avoid this step or perhalps somone can comment.
Dim myChart As Graph.Chart
Dim myChartSeries As Graph.Series
Dim mySeriesDataLabel As Graph.DataLabel
Set myChart = Me.myGraph.Object
For Each myChartSeries In myChart.SeriesCollection
For Each mySeriesDataLabel In myChartSeries.DataLabels
mySeriesDataLabel.Font.Name = "Times New Roman"
mySeriesDataLabel.Font.FontStyle = "Normal"
mySeriesDataLabel.Font.Size = 8
Next mySeriesDataLabel
Next myChartSeries
With Me.myGraph.Axes(1).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
With Me.myGraph.Axes(2).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
Without Anchoring:
After Anchoring:

Related

How to get the actual font size used by a chart axis label

I am using a chart (DataVisualization.Charting.Chart) and letting the chart decide the font size for the axes labels (IsLabelAutoFit = True for each axis). After the chart is drawn, I want to know the actual font size used. Microsoft documentation says that LabelStyle.Font is for both Get and Set. However, the Get always returns the default font size (8 pts) rather than the actual font size used. How can I get the true font size used by the chart?
Dim OriginalXLabelFont As Font = thisChart.ChartAreas("ChartArea1").AxisX.LabelStyle.Font
Dim OriginalXTitleFont As Font = thisChart.ChartAreas("ChartArea1").AxisX.TitleFont
I expect the OriginalXLabelFont to be the actual font size used by the chart, but it always just the default size. On the other hand, OriginalXTitleFont properly gives me the actual Title font size that was used. However, the title font is fixed, and does not change dynamically when the chart is drawn. How can I get the axis label font size of the as-drawn chart?
I poked around and found out that the actual font size used by the graph was in a non-public field of the axis call autoLabelFont. To access it I had to use reflection.
Dim OriginalXLabelFont As Font = GetPrivateFieldValue(thisChart.ChartAreas("ChartArea1").AxisX, "autoLabelFont")
...
Private Function GetPrivateFieldValue(ByVal thisObject As Object, ByVal propName As String) As Object
If IsNothing(thisObject) Then Return Nothing
Dim fi As System.Reflection.FieldInfo = thisObject.GetType().GetField(propName, Reflection.BindingFlags.IgnoreCase Or
Reflection.BindingFlags.Public Or Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
If IsNothing(fi) Then Return Nothing
Return fi.GetValue(thisObject)
End Function

How to change position of TXT and dimensions in FTA by VBA

I have small problem, does anyone know how to change position of existing dimensions and Notes in Part/Product using short macro.
I will shortly describe what I want to do and what kind of problem I have.
I have simple model (let say rectangle)
Inside this model I have dimensions and annotations created in FTA.
Next step is to drastically change position of this model (base model in point 0,0,0 and I want tochange it position to 150,10000,80 + rotation)
during this change some dimensions and annotations (Theirs position in 3D) are not fully following after geometry.
Because of that I would like to have simple macro to create new position of my dimensions and annotations after part update.
I have performed some simple tests code bellow
What I have noticed, when I set new position of the text:
Theoretically text change position but in 3D it stays in old position.
When edit my text by double click on it and then click OK my text translates to new position which was set in macro earlier. The same situation is when I would like to change frame of the text or content (I had AAA and I would like to have BBB), it's changes only when I open Text editor.
Set part1 = CATIA.ActiveDocument
Set Selection = part1.Selection
Set VisPropertySet = Selection.VisProperties
Selection.Search ("name='Text.1',all")
' get selected annotation here
Dim anAnnotation As Annotation
Set anAnnotation = CATIA.ActiveDocument.Selection.Item(1).Value
' get annotation on the DrawingText interface
Dim txtAnnotation As DrawingText
Set txtAnnotation = anAnnotation.Text.Get2dAnnot()
' get TPS view that contains annotation on the DrawingView interface
Dim vwTPSView As DrawingView
Set vwTPSView = txtAnnotation.Parent.Parent
' get coordinates on a view
Dim dX ' as Double
txtAnnotation.X = 0
txtAnnotation.Y = 30
txtAnnotation.FrameType = catEllipse
part1.Update
End Sub
Generally using Part.Update refreshes the annotation's position and text but you can also use:
Dim anAnnotation As Annotation
'Code here
anAnnotation.ModifyVisu 'This should work for both Texts and Dimensions
But if the above method does not work, you can try reseting the text on the annotation (It will work only for texts, and not for dimensions)
Dim vwTPSView As DrawingView
'Code here
vwTPSView.Text = vwTPSView.Text
Be carefull with this last methos though. If your text has any parameters or variables inside it, replacing the text will clear it.

Excel VBA changing properties of Form Control on Chart Tab

I have added an Label on my Chart tab, but when I try to change it's font all of the fields are greyed out. I have searched enough but didn't find any solution. I am attaching a screenshot of my chart tab.
I want to change the font properties of this Label 10 on the chart tab. Is there a way I can access the properties by VBA.
To change the text I recorded a macro.
ActiveChart.Shapes("Label 10").Select
Selection.Characters.Text = "Mohit"
ActiveChart.ChartArea.Select
I tried the line code:
Selection.TextFrame.Characters.Font.Size = 20
but it doesn't work. is there a way to change the color and font size of this label ?
Alternate that I am using now
Now I am using Rectangle shape instead of Label. What I wanted to acheive was to display the name of the selected button ( PV , Terrorism or SRCC ) as an indication that this button have been selected. So I clicked PV and my series changed and Rectangle displayed the name of selected Peril.
Now if I select SRCC again the same thing happens.
For the code I only have to change the text of the rectangle every-time a button is pressed as I preset the font and size of text once which remains the same. I wasn't able to change the font and size of text with a label.
ActiveChart.Shapes("Label 10").Select
With Selection
.Characters.Text = "Mohit"
.Font.Size = 20
End With
or you can avoid Select/Selection accessing your Chart object by its name:
With Charts("ChartName").Shapes("Label 10").TextFrame2.TextRange
.Text = "Mohit"
.Font.Size = 20
End With

Word VSTO (VB.NET) - Get the image location, size, etc,?

I am creating an add-in using VB.NET VSTO for MS-Word. In this program I need to retrieve the details such as Location (Left, Top) and Size (Height, Weight) of all the images on the document. I also want to retrieve the page number where the image is located. I use the following code,
Dim i As Integer
For i = 1 To Globals.ThisAddIn.Application.ActiveDocument.InlineShapes.Count
If Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).Type = Word.WdInlineShapeType.wdInlineShapePicture Then
strHeight = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).ScaleHeight()
strWidth = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i).ScaleWidth()
End If
Next i
However, this can only retrieve the Size (Height, Weight). How to get the Location (Left, Top) and page number of the image?
By its very nature, an InlineShape doesn't have a positionable top and left. It's, well, inline, which means it exists in the text layer of the document and the location floats depending on the text and/or other content before it. If the item is on page 2, and you insert 25 lines of text or another picture before InlineShape(i), said shape will float down to page 3 (or 4 or whatever.)
The height and width ARE accessible, simply by using .Height and .Width. ScaleHeight and ScaleWidth are properties that reflect the size of the object in the document relative to the original size of the object. You probably want to store the height and width as strings, though, since the property returns a single (numeric) value. For height and width:
Dim i As Integer
Dim shp as InlineShape
For i = 1 To Globals.ThisAddIn.Application.ActiveDocument.InlineShapes.Count
shp = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes(i)
If shp.Type = Word.WdInlineShapeType.wdInlineShapePicture Then
strHeight = shp.Height.ToString()
strWidth = shp.Width.ToString()
End If
Next i
To get the page number, you have to reference the range of the InlineShape.
shp.Range.get_Information(Word.WdInformation.wdActiveEndPageNumber)
You can also get the top and left position of the image (although it might not do you any good, depending on why you want it). The get_Information method also has wdHorizontalPositionRelativeToPage and wdVerticalPositionRelativeToPage

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