- Joined
- Nov 9, 2021
- Messages
- 1
- Reaction score
- 0
Hello All! I'm new here ... I have been using VBA with Access for years. I've dabbled just a bit in VBA with Excel. The only VBA I've used in Word has been code I've found on-line and used as is. This time, I want to modify the code I found on-line. I've tried a few things with no luck. I'm quite sure you experts will look at what I want to do and know the correct syntax in three seconds!
What I want to do is create a listing of all the fonts available on my computer along with sample text. I found code that does exactly that. Whoo Hoo!
However, I would like to change the spacing and perhaps change the font size.
Here is what I get with the un-modified code:
The sample text {in the first font} <-- this uses the Normal style
The sample text {in the second font}
The sample text {in the third font}
When I look at this, My brain automatically assumes that the font name closest to the sample text is the font used for the sample text. What I would like to see instead is:
I've tried adding vbCrLf or vbCr in various places with no luck. I think maybe it has to do with the style properties, but I'm not sure.
I have also tried modifying the Heading 2 and Normal style ... although I will say I couldn't modify either to get what I wanted, just some very minor spacing changes. Also, the new document created used the default styles anyway. I don't want to change the default styles across the board.
Here is the code I'm using:
Where and what should I add/change to get the spacing I want?
Thank you ever so much!
Susie
Kansas
What I want to do is create a listing of all the fonts available on my computer along with sample text. I found code that does exactly that. Whoo Hoo!
However, I would like to change the spacing and perhaps change the font size.
Here is what I get with the un-modified code:
The first font name <-- this uses the Heading 2 style
The sample text {in the first font} <-- this uses the Normal style
The second font name
The sample text {in the second font}
The third font name
The sample text {in the third font}
When I look at this, My brain automatically assumes that the font name closest to the sample text is the font used for the sample text. What I would like to see instead is:
The first font name <-- this uses the Heading 2 style
The sample text {in the first font} <-- this uses the Normal styleThe second font name
The sample text {in the second font}The third font name
The sample text {in the third font}I've tried adding vbCrLf or vbCr in various places with no luck. I think maybe it has to do with the style properties, but I'm not sure.
I have also tried modifying the Heading 2 and Normal style ... although I will say I couldn't modify either to get what I wanted, just some very minor spacing changes. Also, the new document created used the default styles anyway. I don't want to change the default styles across the board.
Here is the code I'm using:
Code:
Sub List_All_Fonts()
'Code copied from BrainBell.com November 2021
'https://www.brainbell.com/tutorials/ms-office/Word/Print_Samples_Of_Each_Font_Installed_On_Your_PC.htm
'Lists all the fonts available to Word with the current printer driver
Dim strFont As Variant
Dim strText As String
strText = InputBox(Prompt:= _
"Type the sample text you want to use in the font listing:", _
Title:="List All Fonts", _
Default:="The five boxing wizards jump quickly.")
If strText = "" Then Exit Sub
Documents.Add
For Each strFont In FontNames
Selection.Font.Reset
Selection.TypeText strFont & "parahere"
Selection.Font.Name = strFont
Selection.TypeText strText & vbCr
Next
ActiveDocument.Content.Select
Selection.Sort FieldNumber:="Paragraphs", _
SortFieldtype:=wdSortFieldAlphanumeric
With Selection.Find
.ClearFormatting
.MatchCase = False
.MatchAllWordForms = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchWildcards = False
.Forward = True
.Wrap = wdFindContinue
.Text = "parahere"
.Replacement.Text = "parahere^p"
.Execute Replace:=wdReplaceAll
.Text = "parahere"
.Replacement.Style = "Heading 2"
.Execute Replace:=wdReplaceAll
.Replacement.ClearFormatting
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
.Text = ""
End With
Selection.Collapse Direction:=wdCollapseStart
Selection.Paragraphs(1).Style = "Heading 1"
Selection.TypeText "List of Fonts Available to Word" & vbCr 'I added the & vbCr in order to add a space after this heading
MsgBox "The macro has created a list showing the fonts currently " _
& "available to Word." & vbCr & vbCr & _
"Please save this document if you want to keep it.", _
vbOKOnly + vbInformation, "List All Fonts Macro"
End Sub
Where and what should I add/change to get the spacing I want?
Thank you ever so much!
Susie
Kansas