Example VBA Code:**'The width of a pixel in Excel's userform coordinates

**'thanks to Stephen Bullen

**Public Property Get PointsPerPixelX() As Double

****** Dim hDC As Long

****** hDC = GetDC(0)

****** 'A point is defined as 1/72 of an inch and LOGPIXELSX returns

****** 'the number of pixels per logical inch, so divide them to give

****** 'the width of a pixel in Excel's userform coordinates

****** PointsPerPixelX = 72 / GetDeviceCaps(hDC, LOGPIXELSX)

****** ReleaseDC 0, hDC

**

**

**End Property

**

**

**'The width of a pixel in Excel's userform coordinates

**'thanks to Stephen Bullen

**Public Property Get PointsPerPixelY() As Double

****** Dim hDC As Long

****** hDC = GetDC(0)

****** 'A point is defined as 1/72 of an inch and LOGPIXELSX returns

****** 'the number of pixels per logical inch, so divide them to give

****** 'the width of a pixel in Excel's userform coordinates

****** PointsPerPixelY = 72 / GetDeviceCaps(hDC, LOGPIXELSY)

****** ReleaseDC 0, hDC

**End Property

**

Example VBA Code:**Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

**Private Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hDC As Long, ByVal _

**nIndex As Long) As Long

**Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal _

**hDC As Long) As Long

**Private Const LOGPIXELSX = 88

**Private Const LOGPIXELSY = 90

## Like this thread? Share it with others