Hi all, I am in need of help with the below script, I didn’t write it myself - I wouldn’t know where to start.
When I was given this code it worked perfectly and printed all of the Fonts available on my PC.
Since then I have added more Fonts, but it doesn’t work. The problems are listed below the code.
Thanks for any help. Regards Malcolm.
Clear-Host
$word = New-Object -ComObject “Word.Application”
$word.Visible = $true
$document = $word.Documents.Add()
$sorted = $word.FontNames | sort
for ($i=0;$i -lt $word.FontNames.Count;$i++ ) {
$p = $document.Paragraphs.Add()
$p.Range.Text = $sorted[$i] + " ($i) - "
$p.Range.Font.Name = “Arial”
$p.Range.Font.Size = 20
$f=$p.Range.End
$p.Range.InsertAfter(“ABCDEFGabcdefg1234567890”)
$t=$p.Range.End
$p.Range.InsertParagraphAfter()
$document.Range(ref,[ref]$t).Font.Name = $sorted[$i] }
At C:\Users\malco\OneDrive\Documents\Print_All_Fonts.ps1:2 char:9
- $word = New-Object -ComObject “Word.Application”
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ResourceUnavailable: ( [New-Object], COMException
- FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
The property ‘Visible’ cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\malco\OneDrive\Documents\Print_All_Fonts.ps1:3 char:1
- $word.Visible = $true
-
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\malco\OneDrive\Documents\Print_All_Fonts.ps1:4 char:1
- $document = $word.Documents.Add()
-
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull