Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

col width/row height vs inches 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi, all:

Is there a rule of thumb conversion on the col width and row height to inches?

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Assuming you're asking about Excel, it's just plain awkward. Row heights are in points (1" = 72 points), and column widths are in characters - on a default system 12.86 characters = 1 inch. Microsoft explain some of it here:

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Looking at something else, I just realised that although the UI uses the character unit, VBA gets and sets column widths in points - default width is 48 pixels (=2/3 inch).


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
You could also do an auto calculation of pixels to points...

I wrote this for auto-dual screening excel, making the first 2 workbooks resized to each monitor. I have 2 different sized monitors and needed it to calculate the sizes, and I had planned this for distribution, some people had 2 of the same, and other people had Large fonts turned on (which changes the DPI and therefore the pix->pts ratio).

It is designed as part of an add-in and references ThisWorkbook to hold some variables for toggle functionality (like which screen Excel was on before this was activated.. etc)


-Declare
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long



Public Sub DualScreen()

'References
' '
Dim MidScreen As Double, AppLocLeft As Double, AppLocHeight As Double, AppLocWidth As Double, StrtLoc As Double
Dim PriWidth As Double, SecWidth As Double, MaxPtWidth As Double, MaxPtHeight As Double, SmallHeight As Double, MinWidth As Double
Dim Px As Long, Py As Long, Vx As Long, Vy As Long
Dim NumMonFactor As Variant

'Get monitor sizes in Pixels
Px = GetSystemMetrics(0) 'Primary screen x
Py = GetSystemMetrics(1) 'Primary screen y
Vx = GetSystemMetrics(78) 'Virtual screen x
Vy = GetSystemMetrics(79) 'Virtual screen y

'Gets the DPI settings and calculates Pt to Px conversion factor
hDC = GetDC(0)
PtPx = 72 / GetDeviceCaps(hDC, 88)

'Calculate Screen Points
PriWidth = Px * PtPx
SecWidth = (Vx - Px) * PtPx
MaxPtWidth = Vx * PtPx
If Py > Vy Then
SmallHeight = Vy * PtPx - 50 'compensate for taskbar
MaxPtHeight = Py * PtPx
Else
SmallHeight = Py * PtPx - 50
MaxPtHeight = Vy * PtPx
End If

If ThisWorkbook.Worksheets(1).Range("B5").Value = "" Then
ThisWorkbook.Worksheets(1).Range("B5").Value = False
End If

If GetSystemMetrics(80) = 1 Then
'You do not have Dual Monitors, so we'll split your screen
NumMonFactor = 2
Else
NumMonFactor = 1
End If


Select Case ThisWorkbook.Worksheets(1).Range("B5").Value

Case True
Select Case ThisWorkbook.Worksheets(1).Range("B6").Value
Case Is > PriWidth
StrtLoc = PriWidth + (SecWidth / 2)
MinWidth = SecWidth
Case Is < PriWidth
StrtLoc = 0
MinWidth = PriWidth
End Select
'Restore to single monitor
With Application
.WindowState = xlNormal
.Left = StrtLoc
.Width = MinWidth
.WindowState = xlMaximized
On Error Resume Next
.ActiveWindow.WindowState = xlMaximized
End With

'Set the Dual indicator
ThisWorkbook.Worksheets(1).Range("B5").Value = False

Case False
'Current Visual settings
'+100 to the left value to compensate for minor graphical calculation when restoring from Maximized
ThisWorkbook.Worksheets(1).Range("B6").Value = Application.Left + 100

'Apply Dual Screen
With Application
.WindowState = xlNormal
.Left = 0
.Top = 0
.Width = MaxPtWidth
.Height = SmallHeight
End With

ArrangeTile

On Error Resume Next
'Restructure the first 2 workbooks to fit the screens
Application.Windows(1).Width = (PriWidth / NumMonFactor)
With Application.Windows(2)
.Left = Application.Windows(1).Width + 1
.Width = SecWidth
End With

'Set the Dual indicator
ThisWorkbook.Worksheets(1).Range("B5").Value = True

End Select

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top