web-updates-kmu-pixellaenge-im-excel-berechnen

Pixellänge in Excel berechnen / Calculate Pixellength in Excel (SEO)

Google arbeitet nicht mit Anzahl Zeichen, sondern mit der Länge der Texte. Dies ist nicht immer einfach zu bestimmen. In Excel steht dazu zum Beispiel keine Funktion bereit, so musste Abhilfe her.

Makros können im Excel wie folgt eingefügt werden:

  • Mit der Stastenkombination „ALT + F11" ruft man die Makros auf
  • Oben Links kann mit Rechtsklick auf VBAProjekt … kann per „Einfügen -> Modul" ein neues Modul eröffnet werden
  • Kopiert den untengenannten Code in das neue leere Fenster und schliesst das VBA Projekt Fenster wieder

Google doesn't work with the quantity of characters, but with the poixellength of the string. That is not all the time easy to determine. In Excel there is no standard function for that issue. I needed to find a solution

Makros can be added in Excel this way:

  • With the Keycombinition „ALT + F11" can the Macro windows get opened
  • On Top Left rightclick on VBAProjekt … and choose Insert -> Modul
  • Copy the code down below in the Modul window and close the VBA Window again
'Option Explicit
'API Declares
Private Declare PtrSafe Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare PtrSafe Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32.dll" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As FNTSIZE) As Long
Private Declare PtrSafe Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare PtrSafe Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long

Private Const LOGPIXELSY As Long = 90
Private 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 As String * 32
End Type

Private Type FNTSIZE
 cx As Long
 cy As Long
End Type

Public Function GetPixelLen(text As String, Optional fontName As String = "Arial", Optional fontSize As Single = 20, Optional isBold As Boolean = False, Optional isItalics As Boolean = False) As Integer
 Dim font As New StdFont
 Dim sz As FNTSIZE
 font.Name = fontName
 font.Size = fontSize
 font.Bold = isBold
 font.Italic = isItalics
 sz = GetLabelSize(text, font)
 GetPixelLen = sz.cx
End Function

Private Function GetLabelSize(text As String, font As StdFont) As FNTSIZE
 Dim tempDC As Long
 Dim tempBMP As Long
 Dim f As Long
 Dim lf As LOGFONT
 Dim textSize As FNTSIZE
 tempDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0)
 tempBMP = CreateCompatibleBitmap(tempDC, 1, 1)
 DeleteObject SelectObject(tempDC, tempBMP)
 lf.lfFaceName = font.Name & Chr$(0)
 lf.lfHeight = -MulDiv(font.Size, GetDeviceCaps(GetDC(0), 90), 72) 'LOGPIXELSY
 lf.lfItalic = font.Italic
 lf.lfStrikeOut = font.Strikethrough
 lf.lfUnderline = font.Underline
 If font.Bold Then lf.lfWeight = 800 Else lf.lfWeight = 400
 f = CreateFontIndirect(lf)
 DeleteObject SelectObject(tempDC, f)
 GetTextExtentPoint32 tempDC, text, Len(text), textSize
 DeleteObject f
 DeleteObject tempBMP
 DeleteDC tempDC
 GetLabelSize = textSize
End Function

Anschliessend steht die Funktion zur Verfügung:

  • GetPixelLen( Feld oder Text ; Schriftart (optional) ; Schriftgrösse (optional) )

Damit lässt sich die Länge von Meta Title und Meta Description optimal auswerten:

  • Meta Title 200 - 561 Pixel (Arial Grösse 20)
  • Meta Description: 400 - 985 Pixel (Arial Grösse 14)

Leider appliziert Google noch Zoom auf die Schriften, dass diese kleiner sind, als diese sollten, um diesem rechnung zu tragen, muss mit anderen Grössen/Faktoren gearbeitet werden.

Now the follosing function is implemented:

  • GetPixelLen( Field or string ; Front (optional) ; Font Size (optional) )

With that function, you can now easy implement SEO Rules in Excel:

  • Meta Title 200 - 561 Pixel (ArialSize 20)
  • Meta Description: 400 - 985 Pixel (Arial Size 14)

As Google zoom there Fonts, we need to work with changed font size and factors to get the correct pixelsizes.

AB
1Dies ist ein Title Text=GetPixelLen(A1; "Arial"; 15)*0.8058Es ist möglich, dass ; gegen , getauscht werden muss
2That is the Meta Description=GetPixelLen(A2, "Arial", 11)*0.978689It is possible, that you need to use , instead of ; as of language diffrencies in Excel

In unserem SEO MassEdit für WordPress kann eine verbesserte Funktion auch genutzt werden, um die nötigen Angaben in Pixellänge angezeigt zu bekommen und im Excel direkt zu sehen, ob die Texte in richtiger Länge vorliegen.

Das Plugin ermöglicht weiterhin sehr einfach alle SEO Texte auf Knopfdruck runter und erneut hochzuladen.

An enhanced function can also be used in our SEO MassEdit für WordPress Plugin to see the length of the SEO texts directly in Excel.

With the plugin, its very easy to download and upload all SEO Texts with one click, while have the option to edit everything in Excel.

web updates kmu GmbH-wuk-WordPress und SEO Agentur - Stefan Murawski Beratungen

Fazit: Pixellänge in Excel berechnen

Die oben aufgezählten Punkte sind wichtige für die richtige Länge der Meta Description für Google. Haben Sie Ihre Meta Description ausgefüllt?

Vielleicht ist gerade jetzt der richtig Zeitpunkt für ein Beratungsgespräch mit einer zuverlässigen und kompetenten Webagentur mit dem Fokus auf SEO (Suchmaschinenoptimierung)?

Stellen Sie uns Ihre Fragen, erzählen Sie von Ihren Zielen, gerne hören wir Ihnen zu und beantworten Ihre offenen Fragen.