標題:
[發問]
Excel 播放四個分頁
[打印本頁]
作者:
fantersy
時間:
2016-6-13 17:06
標題:
Excel 播放四個分頁
各位先進好
有一問題想請教
小弟有四個分頁都在同一個檔案
想使用巨集讓四個分頁都能分別出現
就像PPT檔一樣輪播
小弟用了
Application.Wait waitTime
做延遲5秒後再其它分頁
但會卡住....
用了
Application.OnTime Now + TimeValue("00:00:05"), "我的分頁"
一樣會卡住
請問有別的語法或者小弟那邊寫錯了嗎?
作者:
fantersy
時間:
2016-6-13 17:37
回復
1#
fantersy
各位先進好!!
小弟用下列語法寫出...
是可以執行....
請問有更好的寫法嗎??
另外可以設定熱鍵開始跟關閉嗎?
Sub 輪播()
For X = 1 To 5
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5 + X
newSecond1 = Second(Now()) + 10 + X
newSecond2 = Second(Now()) + 15 + X
newSecond3 = Second(Now()) + 20 + X
waitTime = TimeSerial(newHour, newMinute, newSecond)
waitTime1 = TimeSerial(newHour, newMinute, newSecond1)
waitTime2 = TimeSerial(newHour, newMinute, newSecond2)
waitTime3 = TimeSerial(newHour, newMinute, newSecond3)
Sheets("生產日報表-焊錫線").Select
ActiveWindow.ScrollColumn = 1
Application.Wait waitTime
Sheets("生產日報表-組立一線").Select
ActiveWindow.ScrollColumn = 1
Application.Wait waitTime1
Sheets("生產日報表-組立二線").Select
ActiveWindow.ScrollColumn = 1
Application.Wait waitTime2
Sheets("生產日報表-測試線").Select
ActiveWindow.ScrollColumn = 1
Application.Wait waitTime3
Next
End Sub
作者:
stillfish00
時間:
2016-6-14 09:56
回復
2#
fantersy
以下放在ThisWorkbook , 開檔案時定義好熱鍵
Private Sub Workbook_Open()
Application.OnKey "^+a", "AutoPlay" 'Ctrl + Shift + a 開始
Application.OnKey "^+s", "StopPlay" 'Ctrl + Shift + s 停止
End Sub
複製代碼
以下放在一般模組
Private inPlay As Boolean
Private nextTime As Date
Private index As Long
Sub AutoPlay()
StopPlay 'stop previous schedule
inPlay = True
index = 1
LoopDisplaySheet
End Sub
Sub StopPlay()
If inPlay Then
Application.OnTime nextTime, "LoopDisplaySheet", , False '取消已存在排程
inPlay = False
End If
End Sub
Sub LoopDisplaySheet()
Application.Goto Sheets(index).Range("A1"), True
If index = Sheets.Count Then
Exit Sub
Else
nextTime = Now + TimeValue("00:00:01")
index = index + 1
Application.OnTime nextTime, "LoopDisplaySheet"
End If
End Sub
複製代碼
作者:
fantersy
時間:
2016-6-14 13:31
回復
3#
stillfish00
好厲害的寫法!!
謝謝大大的幫忙~真的受教了
學到不少~感恩!!
作者:
fantersy
時間:
2016-6-14 13:53
回復
3#
stillfish00
stillfish00 大大你好!!
小弟剛測試了一下!!
1.所有分頁都能輪放一次, 請問能指定某些分頁嗎?
2.輪放一次後即停止,請問能一直輪放到下熱鍵停止後才停的動作嗎?
抱歉!!麻煩大大解惑
作者:
stillfish00
時間:
2016-6-14 17:20
回復
5#
fantersy
Private nextTime As Date
Private index As Long
Sub AutoPlay()
StopPlay 'stop previous schedule
index = 0
LoopDisplaySheet
End Sub
Sub StopPlay()
On Error Resume Next
Application.OnTime nextTime, "LoopDisplaySheet", , False '取消已存在排程
End Sub
Sub LoopDisplaySheet()
Dim arSheets
arSheets = Array("工作表1", "工作表2", "工作表3")
Application.Goto Sheets(arSheets(index)).Range("A1"), True
If index = UBound(arSheets) Then
index = 0
Else
index = index + 1
End If
nextTime = Now + TimeValue("00:00:01")
Application.OnTime nextTime, "LoopDisplaySheet"
End Sub
複製代碼
作者:
fantersy
時間:
2016-6-16 20:46
回復 fantersy
stillfish00 發表於 2016-6-14 17:20
謝謝大大的幫忙
真的很受用!!感恩!!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)