Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2014, 12:10 AM
Catty Catty is offline CommandBars in powerpoint Windows 7 32bit CommandBars in powerpoint Office 2010 32bit
Advanced Beginner
CommandBars in powerpoint
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default CommandBars in powerpoint

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
Reply With Quote
  #2  
Old 02-24-2014, 02:48 AM
JohnWilson JohnWilson is offline CommandBars in powerpoint Windows 7 64bit CommandBars in powerpoint Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,913
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

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.
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #3  
Old 02-24-2014, 03:13 AM
Catty Catty is offline CommandBars in powerpoint Windows 7 32bit CommandBars in powerpoint Office 2010 32bit
Advanced Beginner
CommandBars in powerpoint
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 02-24-2014, 05:08 AM
JohnWilson JohnWilson is offline CommandBars in powerpoint Windows 7 64bit CommandBars in powerpoint Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,913
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

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
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #5  
Old 02-25-2014, 07:22 AM
Catty Catty is offline CommandBars in powerpoint Windows 7 32bit CommandBars in powerpoint Office 2010 32bit
Advanced Beginner
CommandBars in powerpoint
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

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.
Reply With Quote
Reply



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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft