Private Sub Image1_Click()
Dim aRandomArray(), aTempArray() As Integer
Dim iSlideCount As Integer, iRandomNumber As Integer, i As Integer
iSlideCount = ActivePresentation.Slides.Count 'Get count of slides
ReDim aTempArray(iSlideCount), aRandomArray(0 To iSlideCount, 1 To 1) 'Redeclare array size
'Initialize Temp Array with count-up integer
For i = 0 To iSlideCount - 1
aTempArray(i) = i
Next i
'Generate random number based on iSlideCount
Randomize (Timer)
For i = iSlideCount - 1 To 0 Step -1
iRandomNumber = Int(i * Rnd)
aRandomArray(iSlideCount - i, 1) = aTempArray(iRandomNumber) + 1
If aRandomArray(iSlideCount - i, 1) > 1 Then SlideShowWindows(1).View.GotoSlide aRandomArray(iSlideCount - i, 1) 'Pass first title slide
aTempArray(iRandomNumber) = aTempArray(i)
Next i
SlideShowWindows(1).View.GotoSlide 1 'Return to first slide
SlideShowWindows(Index:=1).View.Exit 'End of presentation
End Sub作者: ychuang 時間: 2017-7-3 01:53
#If VBA7 And Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#End If
Private Sub Image1_Click()
Dim aRandomArray(), aTempArray() As Integer
Dim iSlideCount As Integer, iRandomNumber As Integer, i As Integer
Dim iKey As Integer
iSlideCount = ActivePresentation.Slides.Count 'Get count of slides
ReDim aTempArray(iSlideCount), aRandomArray(0 To iSlideCount, 1 To 1) 'Redeclare array size
'Initialize aTempArray with count-up integer
For i = 0 To iSlideCount - 1
aTempArray(i) = i
Next i
'Generate random number based on iSlideCount
Randomize (Timer)
For i = iSlideCount - 1 To 0 Step -1
iRandomNumber = Int(i * Rnd)
aRandomArray(iSlideCount - i, 1) = aTempArray(iRandomNumber) + 1
If aRandomArray(iSlideCount - i, 1) > 1 Then SlideShowWindows(1).View.GotoSlide aRandomArray(iSlideCount - i, 1) 'Bypass first title slide
'Press [ESC] key or combined [Ctrl+C] keys to cancel the presentation
If GetAsyncKeyState(vbKeyEscape) Or (GetAsyncKeyState(vbKeyControl) & GetAsyncKeyState(vbKeyC)) Then Exit For
Sleep( 2 * 1000) 'Delay 2 seconds
aTempArray(iRandomNumber) = aTempArray(i)
Next i
SlideShowWindows(1).View.GotoSlide 1 'Return to first slide
SlideShowWindows(Index:=1).View.Exit 'End of presentation
End Sub