temporary font install

B

Bruce Hensley

I am creating templates for use on our intranet using Word and Excel 2000 on
Win 2000.

I need a template to temporarily install a Type 1 font from our fileserver
for use while the document is open; I cannot have users install fonts
manually and I don't have a TrueType version.

After much Googling, the following is what I have come up with. It throws
no errors, but it always returns 0 (meaning no font installed) and the font
list in Word never shows the font.

Any suggestions or alternatives would be greatly appreciated.

Thanks,
Bruce

'----------
Private Declare Function AddFontResource Lib "gdi32" Alias
"AddFontResourceA" (ByVal lpFileName As String) As Long
Private Declare Function RemoveFontResource Lib "gdi32" Alias
"AddFontResourceA" (ByVal lpFileName As String) As Long
Const FONTFILE =
"\\server\share\folder\fontname.PFB|\\server\share\folder\fontname.PFM"
Dim tmp As Long

Private Sub Document_Close()
tmp = RemoveFontResource(FONTFILE)
MsgBox tmp
End Sub

Private Sub Document_New()
MsgBox FONTFILE
tmp = AddFontResource(FONTFILE)
MsgBox tmp
End Sub

Private Sub Document_Open()
tmp = AddFontResource(FONTFILE)
MsgBox tmp
End Sub
 
B

Bruce Hensley

I was able to find a TrueType version of the font. The following code
installed it temporarily. There is no need to use RemoveFontResource to get
rid of it. SendMessage seems to be needed to make the font available in
documents created from the template.


Private Declare Function AddFontResource Lib "gdi32" Alias
"AddFontResourceA" (ByVal lpFileName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Const HWND_BROADCAST = &HFFFF&
Const WM_FONTCHANGE = &H1D
Const FONTFILE = "\\server\share\fonts\font.ttf"

Private Sub Document_New()
AddFontResource FONTFILE
SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
End Sub

Private Sub Document_Open()
AddFontResource FONTFILE
SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
End Sub
 
K

Karl E. Peterson

Bruce said:
I was able to find a TrueType version of the font. The following code
installed it temporarily. There is no need to use RemoveFontResource
to get rid of it. SendMessage seems to be needed to make the font
available in documents created from the template.

You might find this instructive:
http://vb.mvps.org/samples/FontPre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top