Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Declare Function MoveWindow Lib "user32" _
- (ByVal hWnd As Long, _
- ByVal x As Long, ByVal y As Long, _
- ByVal nWidth As Long, ByVal nHeight As Long, _
- ByVal bRepaint As Long) As Long
- Private Declare Function ShowWindow Lib "user32" _
- (ByVal hWnd As Long, ByVal nCmdShow As Integer) As Boolean
- Const SW_NORMAL = 1
- Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
- ByVal uAction As Long, ByVal uParam As Long, _
- ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
- Public Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Public Const SPI_GETWORKAREA = 48
- Sub TileHorizontal()
- Dim ttlHeight As Integer 'Word画面の横幅
- Dim ttlWidth As Integer 'Word画面の縦幅
- Dim indivWidth As Integer '個別のファイルの横幅
- Dim i As Integer: i = 1 '※Forをやめて、For eachを使うため
- Dim nDoc As Integer '開かれているファイルの数
- '開かれているファイルの数を取得
- nDoc = Documents.count
- If nDoc < 1 Then Exit Sub
- ' ※ 作業領域(タスクバーを除くディスプレイ領域)を計算
- Dim workArea As RECT
- Call SystemParametersInfo(SPI_GETWORKAREA, 0, workArea, 0)
- ttlWidth = workArea.Right - workArea.Left
- ttlHeight = workArea.Bottom - workArea.Top
- Dim windowHandles As New Collection
- Dim windowHandle As Variant '※For eachで代入する為
- Set windowHandles = GetWindowHandlesOfWord
- '個別ファイルの横幅の設定(縦幅は画面全幅)※Documents.CountはWord2010で誤動作する場合あり
- indivWidth = ttlWidth / windowHandles.count
- For Each windowHandle In windowHandles
- Call ShowWindow(windowHandle, SW_NORMAL)
- '※ 有効画面領域の左・上端を基準に
- Call MoveWindow(windowHandle, _
- indivWidth * (i - 1) + workArea.Left, _
- 0 + workArea.Top, _
- indivWidth, _
- ttlHeight, _
- 1)
- i = i + 1
- Next
- End Sub
Add Comment
Please, Sign In to add comment