お世話になります。過去何度かUserFormを指定セル位置に表示する方法について質問 させていただきました。 おかげさまで、以前、藤代千尋にいただいたコードを利用させていただき画面分割され てない状態では正確にUserFormをActiveCell上に表示できるようになりました。 ありがとうござました。
<以前の問い合わせ> http://excelfactory.net/excelboard/excelvba/cfs.cgi?word=96234&andor=and&logs=50.txt
ところが、当初より聞いてはいたのですが、画面分割状態ではうまく機能しません。 下記がいただいたコードをちょこっと変更してActiveCellにUserFormを 表示するコードです。
ActiveWindow_PointToScreenPixelX(また..Y)ルーチンのPoint座標をPixcel座標 に変換する部分の"With ActiveWindow" の部分を分割Windowの番号、Windows(1)とか Windows(2)とかに変更することによってうまくできるのか・・とトライしてみましたが うまく行きません。(そもそもこのロジックを正確に理解できていない・・トホホ) なのですが・・・ 藤原さんには以前もよーく解説していただいたのですが・・・
●質問
1.Point→Pixcel座標変換は分割画面ではどうあがいても出来ない宿命なのでしょうか。
2.もし方法があるならば、アドバイスいただけないでしょうか。(できれば 下記のコードに手直しをしていただければ幸いです。)
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long Private Const LOGPIXELSX = 88 Private Const LOGPIXELSY = 90 Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
'' テスト用プロシージャのための宣言。 Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Sub Set_UserForm()
With UserForm1 .StartUpPosition = 0 .Left = ActiveWindow_PointToScreenPixelX(ActiveCell.Left) .Top = ActiveWindow_PointToScreenPixelY(ActiveCell.Top) .Show End With
End Sub
Private Function Screen_DPIX() As Long Dim hWnd As Long Dim hdc As Long
hWnd = GetDesktopWindow() hdc = GetDC(hWnd) Screen_DPIX = GetDeviceCaps(hdc, LOGPIXELSX) End Function
Private Function Screen_DPIY() As Long Dim hWnd As Long Dim hdc As Long
hWnd = GetDesktopWindow() hdc = GetDC(hWnd) Screen_DPIY = GetDeviceCaps(hdc, LOGPIXELSY) End Function
Public Function ActiveWindow_PointToScreenPixelX(ByVal XPoint As Single) As Single With ActiveWindow ActiveWindow_PointToScreenPixelX = (.PointsToScreenPixelsX(0) + XPoint * (Screen_DPIX / 72) * (.Zoom / 100)) * 72 / Screen_DPIX ' * (1440 / Screen_DPIX) End With End Function
Public Function ActiveWindow_PointToScreenPixelY(ByVal YPoint As Single) As Single With ActiveWindow ActiveWindow_PointToScreenPixelY = (.PointsToScreenPixelsY(0) + YPoint * (Screen_DPIY / 72) * (.Zoom / 100)) * 72 / Screen_DPIY ' * (1440 / Screen_DPIY) End With End Function
この記事にはVBAのコードが含まれています。
緑の太文字→注釈 茶色の太文字→条件分岐 赤の太文字→ループ 青の太文字→その他
++++++++++++++++++++ OS ⇒Windows 2000 Version⇒Excel 2000 ++++++++++++++++++++ |