Guest User

Untitled

a guest
Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Private Declare Function MoveWindow Lib "user32" _
  4. (ByVal hWnd As Long, _
  5. ByVal x As Long, ByVal y As Long, _
  6. ByVal nWidth As Long, ByVal nHeight As Long, _
  7. ByVal bRepaint As Long) As Long
  8. Private Declare Function ShowWindow Lib "user32" _
  9. (ByVal hWnd As Long, ByVal nCmdShow As Integer) As Boolean
  10. Const SW_NORMAL = 1
  11.  
  12. Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
  13. ByVal uAction As Long, ByVal uParam As Long, _
  14. ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
  15. Public Type RECT
  16. Left As Long
  17. Top As Long
  18. Right As Long
  19. Bottom As Long
  20. End Type
  21. Public Const SPI_GETWORKAREA = 48
  22.  
  23. Sub TileHorizontal()
  24. Dim ttlHeight As Integer 'Word画面の横幅
  25. Dim ttlWidth As Integer 'Word画面の縦幅
  26. Dim indivWidth As Integer '個別のファイルの横幅
  27. Dim i As Integer: i = 1 '※Forをやめて、For eachを使うため
  28. Dim nDoc As Integer '開かれているファイルの数
  29.  
  30. '開かれているファイルの数を取得
  31. nDoc = Documents.count
  32.  
  33. If nDoc < 1 Then Exit Sub
  34.  
  35. ' ※ 作業領域(タスクバーを除くディスプレイ領域)を計算
  36. Dim workArea As RECT
  37. Call SystemParametersInfo(SPI_GETWORKAREA, 0, workArea, 0)
  38. ttlWidth = workArea.Right - workArea.Left
  39. ttlHeight = workArea.Bottom - workArea.Top
  40.  
  41. Dim windowHandles As New Collection
  42. Dim windowHandle As Variant '※For eachで代入する為
  43.  
  44. Set windowHandles = GetWindowHandlesOfWord
  45.  
  46. '個別ファイルの横幅の設定(縦幅は画面全幅)※Documents.CountはWord2010で誤動作する場合あり
  47. indivWidth = ttlWidth / windowHandles.count
  48.  
  49. For Each windowHandle In windowHandles
  50. Call ShowWindow(windowHandle, SW_NORMAL)
  51.  
  52. '※ 有効画面領域の左・上端を基準に
  53. Call MoveWindow(windowHandle, _
  54. indivWidth * (i - 1) + workArea.Left, _
  55. 0 + workArea.Top, _
  56. indivWidth, _
  57. ttlHeight, _
  58. 1)
  59.  
  60. i = i + 1
  61. Next
  62. End Sub
Add Comment
Please, Sign In to add comment