Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

temporary font install

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bruce Hensley - 08 Feb 2006 19:05 GMT
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
Bruce Hensley - 09 Feb 2006 20:50 GMT
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

> I am creating templates for use on our intranet using Word and Excel 2000 on
> Win 2000.
[quoted text clipped - 36 lines]
>     MsgBox tmp
> End Sub
Karl E. Peterson - 09 Feb 2006 21:09 GMT
> 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

Signature

Working without a .NET?
http://classicvb.org/


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.