VBA to change Visio font style by font name instead of font index? - vba

I'm hoping to use VBA to change the font style of the texts in shapes(from Calibri to Verdana). Currently I have (a snippet of the code)
Visio.ActivePage.Shapes(1).Characters.CharProps(visCharacterFont) = 235#
235 is the font index for Verdana in my system. However, the font index is very unstable and can change on different computers. Is there a way to change the font style by font name instead, e.g. ...="Verdana"? It's possible in excel, but I couldn't find similar syntax in Visio. Thanks in advance!

You can check what is ID for Verdana font on current PC
Dim Verdana_ID As Integer
Verdana_ID = ActiveDocument.Fonts.Item("Verdana").ID
And after this step set this ID as character's font
Visio.ActivePage.Shapes(1).Characters.CharProps(visCharacterFont) = Verdana_ID

Related

Change a font color of bookmarked range by clicking it

I have Word document with sections and bookmarked ranges. I would like to format range by clicking it (Change font color between black and red). Is that possible with VBA?
You can change the font color in Word in the following way:
ActiveDocument.Paragraphs(1).Range.Font.ColorIndex = wdGreen
To change the font color of selected text in Word you can use the following code:
Selection.Font.ColorIndex = wdRed
You may find the VBA Word: Difference between Font.TextColor and Font.ColorIndex? page helpful.
To detect mouse clicks in a document you'll have to use WinAPI functions. The Word object model doesn't provide anything for that. Read more about that on the Left Click Event in Word thread.

There's any font that doesn't change text len

I need a font that have the same len no matter if the line contains all 1111 or 8888.
Now I'm using the default VB.NET 2010 font and two lines with the same amount of characters have different len.
Any monospace font will do: https://en.wikipedia.org/wiki/Monospaced_font
I personally use Consolas because that is also the default font family used by Visual Studio in the code editor: https://en.wikipedia.org/wiki/Consolas
The easiest way to set the font is via the form's designer: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.font

Font issue with TM symbol in SSRS reports

I have the following code that works correctly, but I need to adjust the font properly.
=IIF(IsNothing(Fields!new_trademarkname.Value),"",Fields!new_trademarkname.Value & ChrW(8482))
The issue is if I use my font "Architecht's Daughter", the ™ symbol does not appear as superscript (small.) If I use Bookman or other ordinary font, this is ok.
Is there a way to rework the formula to have ChrW(8482)) coded with a seperate font? Like the following:
=IIF(IsNothing(Fields!new_trademarkname.Value),"",Fields!new_trademarkname.Value & <font = "arial"> ChrW(8482))
'''
Use another placeholder in the same textbox for your superscript and adjust the font in the toolbox/properties (F4) window:
placeholder1 with your font "Architecht's Daughter":
=IIF(IsNothing(Fields!new_trademarkname.Value),"",Fields!new_trademarkname.Value)
placeholder2 with a regular font:
=IIF(IsNothing(Fields!new_trademarkname.Value),"",ChrW(8482))

Set font style for entire word document - VBA

I'm trying to figure out how to set the font style for an entire word document, exactly the way it's done by choosing a style preset in the menu:
Since I've already made a macro that converts the entire document word for word, what I'm trying to accomplish with this is changing all the preset tiles (Normal, No Spacing, Title, Heading 1, etc.) to match this existing preset, and not the old presets (with the old fonts).
Is this possible, and what object do I modify to accomplish this?
Try this ...
Sub ChgFontInAllStyles()
Dim sty As Word.Style
For Each sty In ActiveDocument.Styles
If sty.InUse And sty.Type = wdStyleTypeParagraph Then
sty.Font.Name = "Arial"
End If
Next
End Sub
What you show in the screen shot is an Office Theme. This is not the same as a Word style, although some of the settings do "filter through" to the built-in styles and custom styles that base on these.
Themes is a complex topic if it's a question of defining a custom theme programmatically. If all you want to do is apply an existing theme, then:
Dim sThemePath as String
sThemePath = "C:\Program Files\Microsoft Office\Document Themes 14\Equity.thmx"
ActiveDocument.ApplyDocumentTheme sThemePath
It's necessary to specify the entire path. In the sample code this is the default path for the built-in Office themes for Office 2010.

Set PPT Font to 'Body' Type

I am not able to paste the entirety of my code, but the crux is that I have a textbox in PPT 2013, myTb, that I have (programmatically) pasted some text into. I now want to perform the following two actions:
See if the original text was the PPT 'body default' font (e.g. 'Calibri (body)' vs. 'Calibri' in the MS Ribbon)
If it was the body default, set the new text to also be the body default.
I can't seem to figure either part out, even though I have experimented with reading/writing from/to most of the Shape.TextFrame[n].TextRange.Font.Name... fields. I also had two confounding points to ask about, regarding the Shape.TextFrame.TextRange.Font.NameComplexScript field:
This field does not seem to be a 'complete' indicator of body-default vs non-body-default font. The reason is that if this textbox is originally the body-default ('Calibri (body)'), it will read '+mn-cs', but then I can change the font to the non-default variant ('Calibri'), and it still reads '+mn-cs'.
I then proceed to change the textbox to an entirely different font, which changes this field to the font's name as expected. However, if I then change back to the body-default font (or any other font, for that matter), this field remains on the previous font's name.
To set the font to the body or heading font, you need to use a weird bit of syntax:
{object}.Font.Name = "+" + FontType + "-" + FontLang
Where:
FontType is "mj" or "mn" for Major (headings) or Minor (body) respectively.
FontLang is "lt", "cs" or "ea" for Latin, Complex Scripts or East Asian
For example to set the font to the theme's body text font for Latin text:
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Name = "+mn-lt"
A bit late to the party, but I found this in case anyone needs it.
Edit: This is C# code, using the Interop PowerPoint namespace.
string headingsThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;
string bodyThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MinorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;