' ---------------------------------------------------------------
' 1. 等待時間

Sub WaitTime(Sec As Integer)
    Application.Wait (Now() + VBA.TimeValue("00:00:" & Sec))
End Sub

' ---------------------------------------------------------------
' 2. 設定標題

Sub SetCaption(Title As String)
    Application.Caption = Title
    ActiveWindow.Caption = vbNullString
End Sub

' ---------------------------------------------------------------
' 3. 視窗大小控制

Sub WindowSizeControl()
    Application.WindowState = xlMinimized
    ActiveWindow.WindowState = xlMinimized
    Application.WindowState = xlNormal
    ActiveWindow.WindowState = xlNormal
    Application.WindowState = xlMaximized
    ActiveWindow.WindowState = xlMaximized
End Sub


' ---------------------------------------------------------------
' 4. 全螢幕顯示

Sub FullScreen()
    With Application
        .DisplayFullScreen = True
        .CommandBars(1).Enabled = False
        .CommandBars("Full Screen").Controls(1).OnAction = "RestoreWindow"
    End With
   
    With ActiveWindow
        .DisplayHeadings = False
        .DisplayHorizontalScrollBar = False
        .DisplayVerticalScrollBar = False
        .DisplayWorkbookTabs = False
    End With
End Sub

' ---------------------------------------------------------------
' 5. 取消全螢幕顯示

Sub CancelFullScreen()
    With Application
        .DisplayFullScreen = False
        .CommandBars(1).Enabled = True
        .CommandBars("Full Screen").Reset
    End With
   
    With ActiveWindow
        .DisplayHeadings = True
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
        .DisplayWorkbookTabs = True
    End With
End Sub

' ---------------------------------------------------------------
' 6. 隱藏視窗

Sub HideWindow()
    Application.Visible = False
    WaitTime (1)
    Application.Visible = True
End Sub

' ---------------------------------------------------------------
' 7. 移動視窗到外界

Sub MoveWindowOutside()
    Application.WindowState = xlNormal
    Application.Left = 10000
    ' form start up position: setup to 2
End Sub

' ---------------------------------------------------------------
' 8. 隱藏指定 Caption 之 excel window
Sub HideWindowByCaption(filename As String)
    Workbooks(filename).Windows(1).Visible = False
    ' Application.Windows(filename).Visible = False
End Sub

' ---------------------------------------------------------------
' 9. 顯示指 定之 caption 之 excel window

Sub ShowWindowByCaption(filename As String)
    Workbooks(filename).Windows(1).Visible = True
    ' Application.Windows(filename).Visible = True
End Sub

' ---------------------------------------------------------------
' 10. 防止使用者干涉巨集進行
Sub DefectUser()
    Application.Interactive = False
    WaitTime (2)
    Application.Interactive = True
End Sub

' ---------------------------------------------------------------
' 11. 截取特定鍵與組合鍵, 此處截取 Ctrl + F5

Sub CtrlF5()
    MsgBox ("Ctrl+F5")
End Sub

Sub FetchCtrlF5()
    Application.OnKey "^{F5}", "CtrlF5"  ' 設定
    Application.OnKey "^{F5}" ' 回復
End Sub

 

edisonx 發表在 痞客邦 PIXNET 留言(0) 人氣()