1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal Hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal Hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal Hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Const WM_CLOSE = &H10
Private Declare Function BringWindowToTop Lib "user32" _
(ByVal Hwnd As Long) As Long
Public Sub ChangeSlide(ByVal hWndStart As Long, _
ByVal WindowText As String, _
ByVal ClassName As String)
Dim Hwnd As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim Obj As PowerPoint.Shape
Dim Graph As Workbook
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
Hwnd = GetWindow(hWndStart, GW_CHILD)
Do Until Hwnd = 0
ChangeSlide Hwnd, WindowText, ClassName
sWindowText = Space$(255)
r = GetWindowText(Hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space$(255)
r = GetClassName(Hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
If (sWindowText Like WindowText) And (sClassname Like ClassName) Then
BringWindowToTop Hwnd
Set PowerPointApp = CreateObject("Powerpoint.Application")
PowerPointApp.Visible = msoTrue
PowerPointApp.ActivePresentation.Slides(2).Select
Exit Sub
End If
Hwnd = GetWindow(Hwnd, GW_HWNDNEXT)
Loop
End Sub
Sub test2()
' en paramètres
' "*Forum*" : le nom du fichier que tu cherches
ChangeSlide 0, "*Forum*", "*PPTFrameClass*"
End Sub |
Partager