以下鏈接有一些VBA代碼,可能能夠指引您朝着正確的方向:Form Positioner。
它更多地參與比我想象的,但如果你需要找到一些Excel的命令欄的高度,以他們爲榜樣下面的VBA代碼可能會有所幫助:
'
' we'll assume that the application's caption bar and the formula
' bar are the same height as the menu bar. If we can't figure that out, use 26 as a default.
'
If Application.CommandBars.ActiveMenuBar.Visible = True Then
DefaultCmdBarHeight = Application.CommandBars.ActiveMenuBar.Height
Else
DefaultCmdBarHeight = cDefaultCmdBarHeight
End If
'
' We have to have a compenstating factor for command bars. Load an array
' with the heights of visible command bars. The index into the array is
' the RowIndex of the command bar, so we won't "double dip" if two or more
' command bars occupy the same row.
'
For Each CmdBar In Application.CommandBars
With CmdBar
If (.Visible = True) And (.Position = msoBarTop) Or (.Position = msoBarMenuBar) Then
If .RowIndex > 0 Then
VCmdArr(.RowIndex) = .Height
End If
End If
If (.Visible = True) And (.Position = msoBarLeft) Then
If .RowIndex > 0 Then
HCmdArr(.RowIndex) = .Width
End If
End If
End With
Next CmdBar
我不知道你可以做到這一點。你可以得到的最接近的是活動窗口('Application.Windows'集合)的'UsableHeight'和'UsableWidth',以及所述窗口的'Top'和'Left'以及主Excel的'Width'和'Height'窗口。這樣你可以在一定程度上獲得非客戶區域。但是,我不知道要知道窗口上方有多少非客戶區域(菜單欄,窗口標題欄等)以及下面有多少(狀態欄) – InBetween 2011-06-08 18:26:55
感謝您的幫助,InBetween! 我沒有看過'UsableHeight'和'UsableWidth',但這是一個很好的建議。可以通過檢測是否顯示狀態欄來推斷狀態欄的數量(假設狀態欄總是固定的高度)。有點'哈克',但如果它是我能做的最好的... – csharpfrood 2011-06-08 23:04:38