Hallo zusammen,
da ich auf dieser Seite sehr ähnliche Themen gefunden habe wie meines wollte ich um Hilfe fragen, um einen Code der mir leider nur in VB.NET vorliegt in VBA zu überführen. Kennt sich da jemand aus?
Schafft das jemand in diesem Forum?
Ich habe versucht einen Anfang zu machen, weiss aber nicht ob das was ich gemacht habe richtig oder falsch ist. Als System nutze ich Win10, Excel 2013, VBA.
Hier der Originalcode in VB.NET inklusive der Verbesserung weiter unten im Thread.
Quelle:https://stackoverflow.com/questions/103725/is-there-a-way-to-programmatically-determine-if-a-font-file-has-a-specific-unico
EDIT: Den habe ich wieder raus genommen weil ich die Meldung bekommen habe "Nachrichtentext ist zu lang".
Und hier das was ich bis jetzt daraus gemacht habe:
In einem separaten Klassenmodul habe ich definiert:
Klassenmodulname: FontRange
Option Explicit
Public Low As UInt16
Public High As UInt16 Dann in einem mormalen Modul sicht es jetzt so aus:
Public Function GetUnicodeRangesForFont(ByVal font As font) As Collection '(Of
' FontRange)
Public Declare PtrSafe Function GetFontUnicodeRanges Lib "gdi32.dll" (ByVal _
hds As IntPtr, ByVal lpgs As IntPtr) As UInteger
'<DllImport("gdi32.dll")> _
'Public Shared Function GetFontUnicodeRanges(ByVal hds As IntPtr, ByVal
' lpgs As IntPtr) As UInteger
End Function
Public Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hDC As _
IntPtr, ByVal hObject As IntPtr) As IntPtr
'<DllImport("gdi32.dll")> _
'Public Shared Function SelectObject(ByVal hDc As IntPtr, ByVal hObject As
' IntPtr) As IntPtr
End Function
RegServe App.Path & "\" & gdi32.dll, True
Dim g As Graphics
Dim hDC, hFont, old, glyphSet As IntPtr
Dim size As UInteger
Dim GURFF As FontRange
Set GURFF = New FontRange
Set GetUnicodeRangesForFont = New Collection
Dim fontRanges As Collection '(Of FontRange)
Dim frs As FontRange
Set fontRanges = New Collection
Set frs = New FontRange
Dim i As Integer
Dim count As Integer
g = Graphics.FromHwnd(IntPtr.Zero)
hDC = g.GetHdc()
hFont = font.ToHfont()
old = SelectObject(hDC, hFont)
size = GetFontUnicodeRanges(hDC, IntPtr.Zero)
glyphSet = Marshal.AllocHGlobal(CInt(size))
GetFontUnicodeRanges(hDc, glyphSet)
'fontRanges = New List(Of FontRange)
count = Marshal.ReadInt32(glyphSet, 12)
For i = 0 To count - 1
Dim range As FontRange
Set range = New FontRange
range.Low = Unsign(Marshal.ReadInt16(glyphSet, 16 + (i * 4)))
range.High = range.Low + Unsign(Marshal.ReadInt16(glyphSet, 18 + (i * _
4)) - 1)
fontRanges.Add (range)
Next
SelectObject(hDc, old)
Marshal.FreeHGlobal (glyphSet)
g.ReleaseHdc (hDC)
g.Dispose()
GetFontUnicodeRanges = fontRanges
End Function
Private Function Unsign(ByVal Input As Int16) As UInt16
If Input > -1 Then
Unsign = CType(Input, UInt16)
Else
Unsign = UInt16.MaxValue - (Not Input)
End If
End Sub
Public Function CheckIfCharInFont(ByVal character As String, ByVal font As _
font) As Boolean
RegServe App.Path & "\" & gdi32.dll, True
Dim intval As UInt16
Dim ranges As Collection '(Of FontRange)
Dim fr As FontRange
Set fr = New FontRange
Set ranges = New Collection
Dim isCharacterPresent As Boolean
Dim range As Object
intval = Convert.ToUInt16(character)
ranges = GetUnicodeRangesForFont(font)
isCharacterPresent = False
For Each range In ranges
If intval >= range.Low And intval <= range.High Then
isCharacterPresent = True
Exit For
End If
Next range
CheckIfCharInFont = isCharacterPresent
End Function Probleme macht denke ich:
1. die Einbindung der dll's. Das ist für mich ganz neu.
2. Die Variablendeklaration font beim Funktionsaufruf CheckIfCharInFont
3. Und die bei mir noch rot markierten Stellen (sieht man wenn man den Code in VBA übernimmt).
Ich würde mich riesig freuen, wenn mir hier jemand helfen könnte.
Vielen Dank. |