![]() |
|
|
|
#1
|
|||
|
|||
|
Hi, I am trying to write a macro that will check if the Header and Footers dialog box is closed. I have tried the below macro but its not working the way i want it to.
I need to run a macro that will close the Slide Master View after the button "Apply to All" in the Headers and Footers Dialogbox has been clicked. Code:
Sub testDialogOpen()
Dim wHandle As Long
Dim wName As String
wName = "Header and Footer"
wHandle = FindWindow(0&, wName)
If wHandle = 0 Then
MsgBox "Dialog window is not open"
Else
MsgBox "Dialog window is open"
End If
End Sub
|
|
#2
|
|||
|
|||
|
Not sure how you are running the code with a modal dialog open.
BUT The header and Footer is a Dialog class window "#32770" so: #If VBA7 Then Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr #Else Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long #End If Sub chex() Dim wName As String Dim hWnd Dim lpClass As String wName = "Header and Footer" lpClass = "#32770" hWnd = FindWindow(lpClass, wName) If hWnd = 0 Then MsgBox "Dialog window is not open" Else MsgBox "Dialog window is open" End If End Sub If you are opening the dialog in code you will need to incorporate a delay before checking to allow the window to open otherwise it will always show as closed. |
|
#3
|
|||
|
|||
|
Hi John, thanks for the response.
I am able to open the dialog window via code, I guess my real issue is incorporating the delay. How would I go about doing this? Currently my macro perfoms the following steps: 1. View 2. Slide master 3. Insert 4. Header & Footer Is there a way for me to access the "Apply to All / Apply / Cancel" buttons on the HeaderFooter dialog? What I need to happen is to check if the above buttons have been selected and then continue with the below macro steps. 5. Slide Master 6. Close Master View |
|
#4
|
|||
|
|||
|
Easiest way to have a delay is to read the timer and loop until iot reaches a set increment.
I don't know a way to check whether Slide Number etc are already checked. I guesss you could insert a slide and see if the number was visible as a check Sub example() Dim wName As String Dim hWnd Dim lpClass As String Dim osld As Slide CommandBars.ExecuteMso ("HeaderFooterInsert") delayMe 0.5 wName = "Header and Footer" lpClass = "#32770" hWnd = FindWindow(lpClass, wName) If hWnd <> 0 Then Set osld = ActivePresentation.Slides.Add(1, ppLayoutTwoColumnText) If Not osld.HeadersFooters.SlideNumber.Visible Then SendKeys "%N" 'tick number SendKeys "%Y" ' Apply to all osld.Delete End If End If End Sub Sub delayMe(sngsec As Single) Dim sngStart As Single sngStart = Timer While sngsec + sngStart > Timer DoEvents Wend End Sub The only way AFAIK to "click" the buttons is to use SendKeys |
|
#5
|
|||
|
|||
|
Hi John,
Thanks so much for all your help. My macro does exactly what I need it to. I've realised that I don't need to first determine if the user has clicked "Apply to All / Apply / Cancel" before closing the Master View. I can close this and still have the dialog window open, then its unfortunately up to the user to click the above buttons. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PowerPoint 2007 --> PowerPoint 2003 Webpage? | josephsh | PowerPoint | 0 | 06-09-2011 11:22 PM |
| MailItem Inspectors cache CommandBars but Calendar do not? | Hydrogen | Outlook | 0 | 03-04-2006 09:50 PM |