檢查使用VBA安裝特定字體的最簡單方法是什麼?如何測試使用VBA安裝字體?
4
A
回答
1
好的,真正的形式我發現這個發現後30秒找到了解決方案。儘管這是訴諸SO前10分鐘的搜索....使用API
2
有
EnumFonts 的EnumFonts函數枚舉一個指定的設備上可用的字體。對於具有指定字體名稱的每種字體,EnumFonts函數會檢索有關該字體的信息並將其傳遞給應用程序定義的回調函數。這個回調函數可以根據需要處理字體信息。繼續枚舉直到沒有更多字體或回調函數返回零。
VB4-32,5,6
Declare Function EnumFonts Lib "gdi32" Alias "EnumFontsA" (ByVal hDC As Long, ByVal lpsz As String, ByVal lpFontEnumProc As Long, ByVal lParam As Long) As Long
或
的EnumFontFamilies函數枚舉在指定的字體系列可用一個指定設備上的字體。該函數取代EnumFonts函數。
VB4-32,5,6
Declare Function EnumFontFamilies Lib "gdi32" Alias "EnumFontFamiliesA" (ByVal hdc As Long, ByVal lpszFamily As String, ByVal lpEnumFontFamProc As Long, ByVal lParam As Long) As Long
示例例程
'In a module
Public Const NTM_REGULAR = &H40&
Public Const NTM_BOLD = &H20&
Public Const NTM_ITALIC = &H1&
Public Const TMPF_FIXED_PITCH = &H1
Public Const TMPF_VECTOR = &H2
Public Const TMPF_DEVICE = &H8
Public Const TMPF_TRUETYPE = &H4
Public Const ELF_VERSION = 0
Public Const ELF_CULTURE_LATIN = 0
Public Const RASTER_FONTTYPE = &H1
Public Const DEVICE_FONTTYPE = &H2
Public Const TRUETYPE_FONTTYPE = &H4
Public Const LF_FACESIZE = 32
Public Const LF_FULLFACESIZE = 64
Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
Type NEWTEXTMETRIC
tmHeight As Long
tmAscent As Long
tmDescent As Long
tmInternalLeading As Long
tmExternalLeading As Long
tmAveCharWidth As Long
tmMaxCharWidth As Long
tmWeight As Long
tmOverhang As Long
tmDigitizedAspectX As Long
tmDigitizedAspectY As Long
tmFirstChar As Byte
tmLastChar As Byte
tmDefaultChar As Byte
tmBreakChar As Byte
tmItalic As Byte
tmUnderlined As Byte
tmStruckOut As Byte
tmPitchAndFamily As Byte
tmCharSet As Byte
ntmFlags As Long
ntmSizeEM As Long
ntmCellHeight As Long
ntmAveWidth As Long
End Type
Declare Function EnumFontFamilies Lib "gdi32" Alias "EnumFontFamiliesA" (ByVal hDC As Long, ByVal lpszFamily As String, ByVal lpEnumFontFamProc As Long, LParam As Any) As Long
Function EnumFontFamProc(lpNLF As LOGFONT, lpNTM As NEWTEXTMETRIC, ByVal FontType As Long, LParam As Long) As Long
Dim FaceName As String
'convert the returned string to Unicode
FaceName = StrConv(lpNLF.lfFaceName, vbUnicode)
'print the form on Form1
Form1.Print Left$(FaceName, InStr(FaceName, vbNullChar) - 1)
'continue enumeration
EnumFontFamProc = 1
End Function
'In a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim hDC As Long
'set graphics mode to persistent
Me.AutoRedraw = True
'enumerates the fonts
EnumFontFamilies Me.hDC, vbNullString, AddressOf EnumFontFamProc, ByVal 0&
End Sub
6
http://www.vbcity.com/forums/topic.asp?tid=57012
重定向到
http://vbcity.com/forums/t/55257.aspx
這VB6代碼是兼容VBA:
Function FontIsInstalled(sFont As String) As Boolean
'' This reference should already be set by default
'' Tools > References > OLE Automation
Dim NewFont As StdFont
On Error Resume Next
Set NewFont = New StdFont
With NewFont
' Assign the proposed font name
' Will not be assigned if font doesn't exist
.Name = sFont
' Return true if font assignment succeded
FontIsInstalled = (StrComp(sFont, .Name, vbTextCompare) = 0)
' return actual font name through arguments
sFont = .Name
End With
End Function
相關問題
- 1. 測試字體是否安裝
- 2. 測試字體是否安裝(Win32)
- 3. 安裝xna後如何使用字體
- 4. 如何使用C#安裝Windows字體#
- 5. 測試正確安裝的sqlite3的安裝使用Rails安裝
- 6. 如何安裝pygame字體
- 7. 如何安裝字體?
- 8. 測試IE7而不安裝它 - 如何?
- 9. 後綴的安裝,但如何測試
- 10. 如何安裝cocos2d 2.0測試版?
- 11. 如何測試Silverlight安裝過程
- 12. 如何測試Adobe AIR是否使用jQuery安裝?
- 13. 使用Inno安裝安裝字體 - 替換已鎖定的字體
- 14. CSS:使用已安裝的字體
- 15. 如何在jasperreports中安裝新字體
- 16. 如何安裝和使用joomla中的新字體
- 17. 如何使用Bower安裝自定義字體? (not Font Awesome)
- 18. Pycharm:我如何使用在Ubuntu中安裝的字體
- 19. 如何導入使用NPM安裝的字體?
- 20. wxPython - 如何在Ubuntu上使用已安裝的字體
- 21. 如何迭代使用JavaScript安裝的字體?
- 22. 如何使用Silverlight在Windows和MAC上安裝字體?
- 23. 安裝後測試perl
- 24. Gallio測試套件安裝
- 25. 在VMWare上測試安裝
- 26. 如何:字體平滑測試
- 27. 卸載安裝使用「測試Installtion流」選項安裝的應用程序
- 28. 如何更改Xcode安裝目標? (例如安裝iOS 4.x測試版)
- 29. 的XCode 9個+ iphone8 +織物不能使用測試版安裝測試應用
- 30. iPhone應用程序測試:如何獲得乾淨的安裝?
這是一個更優雅的解決方案,無需使用API。我強烈推薦它。 – Bobort 2015-03-05 21:24:27
鏈接消失了。它應該是這樣的:http://spreadsheetpage.com/index.php/tip/getting_a_list_of_installed_fonts/ – PatricK 2016-05-03 06:56:06