Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-2008, 02:28 PM
Mystif
 
Posts: n/a
Attempting to "Embed" a font in Excel 2003 - Could use help with VBA code

Hey there everyone,

I do not know what I missed, but I must have missed something...
The code (below) runs without errors in Excel 2003 on Vista and XP. It
does copy the font into the font folder, but it is not registering
right.

At the CMD I can DIR the fonts folder and see that the file is there,
but if I look using explorer it is not visible (not font name or file
name).

For this upload I changed the location of font file to "C:\temp\". The
actual location of the file is on a network server and is accessed via
UNC.

When this codes works as intended it would copy the font, register the
font, and notify all open applications, including Excel, about the
font.

As far as I can tell, this is about as close as you can get to
embedding a font in Excel, unless you have 2007, which I do not.

Finally, the real work being done here is, with only a few small
changes, taken from code I found online. I had to change things like
"user" to "user32" and add aliases to make the errors stop. Without
the "32" it could not find the file, and without the alias it would
say it could not find an entry point.

Thank you, in advance.
Mystif


Private colFoundFiles As New Collection
Private strPath As String

Private Declare Function CreateScalableFontResource Lib "gdi32" _
Alias "CreateScalableFontResourceA" (ByVal fHidden As Long, _
ByVal lpszResourceFile As String, ByVal lpszFontFile As String, _
ByVal lpszCurrentPath As String) As Long

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

Private Declare Function WriteProfileString Lib "Kernel32" Alias _
"WriteProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String) As Integer

Private Sub Workbook_Open()
IsFontInstalled
End Sub

Sub IsFontInstalled()
Dim lngFileCount As Long

strPath = Environ("SystemRoot") & "\Fonts"

With Application.FileSearch
.NewSearch
.LookIn = strPath
.Filename = "astronbv.ttf"
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then
FileCopy "C:\Temp\astronbv.ttf", strPath & "\astronbv.ttf"
Install_TTF "Astron Boy Video", "astronbv.ttf", _
Environ("SystemRoot") & "\System32"
Else
Exit Sub
End If
End With
End Sub

' This sub installs a TrueType font and makes it available to
' all Windows apps. It takes these arguments:
'
' FontName$ is the font's name (e.g. "Goudy Old Style")
'
' FontFileName$ is the font's filename (e.g. "GOUDOS.TTF")
'
' WinSysDir$ is the user's System folder (e.g.
' "C:\WINDOWS\SYSTEM" or "C:\WINDOWS\SYSTEM32")
'
' ** Before calling this sub, your code must copy the font file
' to the user's Fonts folder. **
'
Sub Install_TTF(FontName$, FontFileName$, WinSysDir$)
Dim Ret%, Res&, FontPath$, FontRes$
Const WM_FONTCHANGE = &H1D
Const HWND_BROADCAST = &HFFFF

FontPath$ = Environ("SystemRoot") & "\Fonts\" & FontFileName$
FontRes$ = WinSysDir$ & "\" & Left$(FontFileName$, _
Len(FontFileName$) - 3) & "FOT"

Ret% = CreateScalableFontResource(0, FontRes$, _
FontFileName$, WinSysDir$)
Ret% = AddFontResource(FontRes$)
Res& = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
Ret% = WriteProfileString("fonts", FontName + " " & _
"(TrueType)", FontRes$)
End Sub
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:59 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Personal Loans | Loans | Proxy | Personal Loans | Credit Card



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114