添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Excel Character Width Measurement

A VBA script that measures the pixel width of all printable ASCII characters and records the results in a new Excel sheet.

Description

The VBA macro measures the width of each printable ASCII character (from space to tilde) using the GetTextExtentPoint32 Windows API function and outputs the results to an Excel sheet. This can be particularly useful for tasks that require precise layout designs in Excel, like creating forms or reports.

Requirements

  • Microsoft Excel (The macro was written for the 64-bit version of Excel)
  • Basic knowledge of running macros in Excel
  • License

    This project is licensed under the MIT License - see the LICENSE.md file for details.

    This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
    Show hidden characters Declare PtrSafe Function SelectObject Lib "gdi32" (ByVal hdc As LongPtr, ByVal hObject As LongPtr) As LongPtr Declare PtrSafe Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Integer, ByVal W As Integer, ByVal E As Integer, ByVal O As Integer, ByVal FW As Integer, ByVal i As Integer, ByVal U As Integer, ByVal S As Integer, ByVal C As Integer, ByVal OP As Integer, ByVal CP As Integer, ByVal Q As Integer, ByVal PAF As Integer, ByVal F As String) As LongPtr Declare PtrSafe Function DeleteObject Lib "gdi32" (ByVal hObject As LongPtr) As Long #Else Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, ByRef lpSize As SIZE) As Long Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Integer, ByVal W As Integer, ByVal E As Integer, ByVal O As Integer, ByVal FW As Integer, ByVal I As Integer, ByVal U As Integer, ByVal S As Integer, ByVal C As Integer, ByVal OP As Integer, ByVal CP As Integer, ByVal Q As Integer, ByVal PAF As Integer, ByVal F As String) As Long Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long #End If I tried to run the code but the compiler does not reconize the CreateFont parameters. Is there a workarround?

    Thanks