Excel VBA changing properties of Form Control on Chart Tab - vba

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

Related

VBA Hint Text in UserForm TextBox

How to add a hint text to a TextBox in a UserForm that will disappear once a user type anything in?
Add a Label element.
Type a hint text.
Set BackColor, Height, Left, Top, and Width properties to match that of the TextBox that will be added later.
Note: Setting BackColor to Window Background (from the drop-down list) will match the common background color of a text box.
Set ForeColor property (a different from TextBox text color allows to distinguish the hint text from the entered one).
Add a TextBox element.
Set BackColor, Height, Left, Top, and Width properties.
Set BackStyle property to fmBackStyleTransparent.
Add the following code to Sub TextBox_Change:
If TextBox.Value = "" Then
TextBox.BackStyle = fmBackStyleTransparent
Else
TextBox.BackStyle = fmBackStyleOpaque
End If
Here is the result:

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

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:

How to change style of ONE word to bold in text of RichTextBoxColumn added to DataGridView in vb.net

I have added a RichTextBoxColumn to DataGridView, want to change font style
Bold/Regular Font, ForeColor of a PART OF TEXT. But this does not work like Windows
RichTextBox Control. Please help.
My Code:
With DataGridView1
.Columns(4).DisplayIndex = 4
.Columns(4).ValueType = GetType(DataGridViewRichTextBoxCell)
.Columns(4).Width = 17
.Columns(4).DataGridView.DefaultCellStyle.Font = New Font(FontFamily
Name,
11.0!,System.Drawing.FontStyle.Bold)
End With
But, all Cells in Row get Bold.

Adapt label width to text

I basically programmatically generate many labels with a text read from a text file so I would like to know how I can programmatically adapt the width of a Label to its text.
Controls come in two flavors. The ActiveX version of a label has an AutoSize property. For example, with a ActiveX label control named Label1 in Sheet1
Private Sub test()
Sheet1.Label1.WordWrap = False
Sheet1.Label1.AutoSize = True
Sheet1.Label1.Caption = "This is a lot of text to put in a label"
End Sub
will automatically adjust the width to fit.

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