I have some code which changes all texts in a chart object to a specific size and font. Thing is the first time one runs the code it works like a charm. But if I change any part of the text within the chart and then re-run the code nothing happens.
E.g I run the code, then change the title heading to size 15 and font arial, then rerun macro, and nothing happens.
What can be wrong?
My code
With Selection
.Format.TextFrame2.TextRange.Font.Size = 10
.Format.TextFrame2.TextRange.Font.Name = "Times New Roman"
.Format.TextFrame2.TextRange.Font.Bold = msoFalse
End With
When you apply the fonts/sizes to the ChartArea in order to propagate them down to the individual pieces, Excel stores that info at the CharArea level. If you make a change to the one of the components (ChartTitle, Axis, etc.) and try to run your code again, there is no change on the ChartArea. Seems that Excel does not propagate those changes "back up". This makes sense since now the different items are styled differently.
The easiest way to deal with this is to reset the styles before you make your changes. ClearToMatchStyle applied to the Chart (i.e. ActiveChart or Selection.Parent in your context) will do it. It appears it will also make the change if you use a different font size or actually make a change to one of the ChartArea.Format properties (e.g. Size, Name, etc.).
Code for the reset option
ActiveChart.ClearToMatchStyle
With Selection
.Format.TextFrame2.TextRange.Font.Size = 12
.Format.TextFrame2.TextRange.Font.Name = "Times New Roman"
.Format.TextFrame2.TextRange.Font.Bold = msoFalse
End With
Related
I'm trying to create a form that allows the user to edit text on another form, however only the size OR style (bold, italic etc.) of the font is changed instead of both.
My current code:
fnt = Form1.Label6.Font
Form1.Label6.Font = New Font(fnt.Name, 12)
Putting FontStyle.Bold after means that size will only be bold. This is the same for regular and italic. I have a feeling I'm overlooking something simple but i just can't figure it out.
Thank you
I've got a MS Access form that contains a subreport.
This is to allow a sort of dynamic preview of what you are going to get when you launch the print (in fact it's a form that allows to chose among different print layouts).
Let's say that my report is this:
It has also non-fixed fields, but it's not relevant for this issue.
The report is quite small and when presented in the form I would like to apply some sort of zoom, which actually I can't find.
Even if the subform/subreport control is much larger than the report, there seems not to exist a property that allows you to resize the report.
The result is this:
I tried setting Default View to Print Preview, no changes in visualization.
I hoped that switching to Print Preview would allow a greater control of the zoom (like actually happens when you launch a 'standard' print preview).
I tried setting FitToPage to true.
I tried to set AllowReportView to force the Print Preview, with no luck. At this point i think Print Preview is simply not allowed in a report inside a form.
Is there some (or some other) way to address this smallness problem?
Thanks in advance
P.S. If zooming is not possible, I would at least highlight the real report area because showing only the borders of the subform/subreport control would be confusing in this case.
Correct, report on form can only be displayed in ReportView. I don't think you can get 'zoom' feature by any method. As for 'highlight' of report area, code could set Backcolor property of each report section when report loads, like:
Private Sub Report_Load()
With Me
If .CurrentView = 6 Then
.ReportHeader.BackColor = vbYellow
.ReportFooter.BackColor = vbYellow
.PageHeaderSection.BackColor = vbYellow
.PageFooterSection.BackColor = vbYellow
.GroupHeader0.BackColor = vbYellow
.GroupFooter1.BackColor = vbYellow
.Detail.BackColor = vbYellow
End If
End With
End Sub
Might want to set all controls with transparent BackStyle.
Or instead of setting Backcolor, use a background image (watermark) on report.
In short, the issue I'm running into is that when using VBA to change font size during a presentation, the slide runs all animations for that slide a second time. Changing other qualities, such as font color or shape fill, the slide does not animate a second time.
The longer version: I'm creating a tool in PowerPoint for my trainers to be able to build quizzes and computer-based trainings. I'm using a template shape for each state of the button (correct, incorrect or unanswered), and then have .pickup and .apply to change the formatting of the shapes on the question slides. At runtime, the slide builds based on the animations, the user clicks an option and the shapes format immediately. However, the font size also changes to mirror the template shape. When I temporarily store the font size and reapply it after .apply, at runtime, the slide animates, the user clicks an option and the slide runs the animations again (albeit correctly with the new formatting). The code works, but certain changes cause the slide to animate a second time (text, size), and some changes don't (shape color, text color). It's this second animation of the slide I need to avoid.
Windows 7 Professional;
PowerPoint 2016
Instead of using .pickup & .apply, one thought was to change qualities of everything but the font size, (the fill and line qualities), but for the fill, alone there are 20+ qualities, and that's before getting into number of gradient stops, shadows, etc. I need my developers to have the freedom of formatting the shape as they want that my code can quickly pull from.
.SlideShowSettings.ShowWithAnimation - setting to 'false' at the start of the code and 'true' yielded no change in results. (Attempt shown in code below.)
.SlideShowWindow.View.State - setting to 'paused' and 'running' also did not affect anything. (Attempt shown in code below.)
All objects on the slide are set to fade in automatically upon showing the slide. The simplified code here is set to run when a shape is clicked and shows what works and what doesn't work. I've commented lines in and out so I can try different things.
Sub ProcessResponse()
'These options do not prevent re-animation when in mid-presentation:
'ActivePresentation.SlideShowSettings.ShowWithAnimation = msoFalse
'ActivePresentation.SlideShowWindow.View.State = ppSlideShowPaused
'The following items do NOT cause the slide to run the animation again (desired result):
'Changing the object fill.
'ActivePresentation.Slides(1).Shapes(1).Fill.ForeColor.RGB = RGB(50, 25, 100)
'Changing text color.
'ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Color.RGB = RGB(50, 25, 150)
'The following lines of code cause the slide to run the animation again (undesired result):
'Changing the font size.
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Size = 40
'Changing the text.
'ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text = "Changed"
'Closing the above attempts.
'ActivePresentation.SlideShowSettings.ShowWithAnimation = msoTrue
'ActivePresentation.SlideShowWindow.View.State = ppSlideShowRunning
End Sub
Setup: Slide with animations (i.e., fade in) that run "after next". 3-4 shapes, each with the above code called when clicked.
During the slide show:
Expected - animations, user clicks shape, the changes are made, no further actions/animations.
Actual Result - animations, user clicks shape, animations (changes are included).
Thank you for any and all help and considerations. Your time is appreciated.
I am trying to implement a 'Flag' w/ a menustrip.
I have an image list w/ a red flag and a black flag.
When I click the menu item, i want to toggle the image.
The problem I have is that once I change the image, it wants to do SizeToFit which makes the Icon roughly the height of text. I dont want that. I want the Image to be its actual size.
I have tried putting the statements in different orders, nothing i have tried seems to work.
Currently, I have the button set to the black flag at design time.
This code shows me trying to change to a Red flag.
tsbFlagPatient.Image = ilFlags.Images(1)
tsbFlagPatient.ImageScaling = ToolStripItemImageScaling.None
tsbFlagPatient.DisplayStyle = ToolStripItemDisplayStyle.Image
[If there is some better way to approach toggling the image, im open to that. That seems like a separate question. ]
I was unable to make ImageScrolling work.
Since I dont need text here, I used BackGround Image and set
BackgroundImageLayout = Stretch
This allows the images to be the right size.
You can turn AutoSize = false and then manually set Height, Width to fine tune your menu's size.
I did reconsider the ImageList and changed the images to being stored in the project Resources. This is the code to toggle the image
Public Sub SetFlagImage(flagSet As Boolean)
If flagSet = False Then
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_black
btnFlag.BackgroundImage.Tag = "black"
Else
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_red
btnFlag.BackgroundImage.Tag = "red"
End If
End Sub
This had no effect on the question posed here. In general, probably better than having an image list because all forms can access it.
So I am making a small game in visual basics and at one of the thing I need to do is change the label size following an If statement. Sadly, It seemed way more complicated than I expected... I tried the following but it is "Read only"
If condition = false then
lbltmp.Font.Size = 12pts
end if
I also Tried the following based on my friends advise:
With lbltmp.font
.size = 12
end with
I found similar question but they were all in c#, Which I don't know how to code in yet
You need to change font instead of its size ;) See this: LINQ Cookbook, Recipe 1: Change the font for all labels on a windows form (Kit George)
label.Font = New Font("Comic Sans MS", 12, _
FontStyle.Bold Or FontStyle.Underline)
You have to write this code. This will change the whole property of label.
Yourlabel.Font = New Font("Font Name", 10, FontStyle.Regular)
You could actually change the size of it but you don't use code.
Instead just go to the properties of whatever you're trying to change the font size of, and go to the font property. Click on the 3 dots (...) and a box will open. In that box, you can change the font and its size too. So you could change the size there!
(by the way this is the first time I've given an explanation on a website.)