返回列表 上一主題 發帖

Excel VBA 如何自動調整表單大小

回復 2# stillfish00
加上可還原(原來的大小)
  1. Option Explicit
  2. Dim xME()
  3. Private Sub UserForm_Initialize()
  4.     Dim i As Integer, e As Variant
  5.     ReDim xME(0 To Controls.Count)   
  6.     xME(0) = Array(Top, Left, Height, Width, Font.Size)
  7.     For Each e In Controls
  8.         With e
  9.             i = i + 1
  10.             xME(i) = Array(.Top, .Left, .Height, .Width, .Font.Size)
  11.         End With
  12.     Next
  13. End Sub
  14. Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  15.   Dim i As Integer, e As Variant
  16.   Static lastY As Single
  17.   Debug.Print Shift
  18.     If Button = 1 And Shift = 2 Then
  19.         If Y - lastY > 5 Then
  20.             ResizeUserform 1.1
  21.             lastY = Y
  22.         ElseIf lastY - Y > 5 Then
  23.             ResizeUserform 0.9
  24.             lastY = Y
  25.         End If
  26.     ElseIf Button = 2 And Shift = 2 Then    '按下右鍵
  27.         Top = xME(0)(0)
  28.         Left = xME(0)(1)
  29.         Height = xME(0)(2)
  30.         Width = xME(0)(3)
  31.         Font.Size = xME(0)(4)
  32.         For Each e In Controls
  33.             With e
  34.                 i = i + 1
  35.                 .Top = xME(i)(0)
  36.                 .Left = xME(i)(1)
  37.                 .Height = xME(i)(2)
  38.                 .Width = xME(i)(3)
  39.                 .Font.Size = xME(i)(4)
  40.             End With
  41.         Next
  42.     End If
  43. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2013-7-19 09:45 編輯

回復 8# Jared
Shift   
0 (零) 沒有鍵
1 SHIFT 鍵
2 CTRL 鍵
4 ALT 鍵
  1. If Button = 1 And Shift = 2 Then    '按下左鍵 +Shift

  2.     ElseIf Button = 2 And Shift = 2 Then    '按下右鍵 +Shift
複製代碼
程式碼不了解要多看VBA說明
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 我們最大的敵人不是別人.可能是自己。
返回列表 上一主題