Re: Dialog Boxes in PowerPoint

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

brian_at_nothere_reillyand.com
Date: 03/19/05


Date: Sat, 19 Mar 2005 11:49:12 -0500

Jackie, Here's some code I wrote modifying some of Shyam's other code
to call the API to do just this.

It's on google.

Here's a bit of code that is based on Shyam's example of the Sleep api
call. It opens the Insert Picture from File dialogue and hangs out
till a variable is set to False based on the count of shapes on a
slide since if it didn't wait for the user to insert a picture the
code would be finished running and not insert the selected picture.

Option Explicit

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

''' Comments: This routine uses an API call to Sleep while the
dialog is open.
''' Otherwise the code would continue running before the
user got to insert the picture.
''' Also captures the Cancel button by counting objects
after the dialog closes.
''' Also runs a counter after the dialog closes to capture
the Cancel click which cannot be captured normally.
''' Date Developer Action
''' 2/10/02 Brian Reilly Created

Sub Insert_Picture_on_Title_Dialog­()

    Dim strViewType As String
    Dim lShapeCount As Long
    Dim i As Integer, j As Integer
    Dim iTimeCounter As Integer
    On Error GoTo errorhandler

    strViewType = ActiveWindow.ViewType

    'Check for TitleMaster first
    If ActivePresentation.HasTitleMas­ter = False Then
        MsgBox "This presentation does not have a TitleMaster. Exiting
. . ."
        Exit Sub
    Else
        'Continue
    End If

    lShapeCount = ActivePresentation.TitleMaster­.Shapes.Count

    'Just in the eventuality that you click the start button twice
    'isRunning stores the current state of the macro
    'TRUE = Running; FALSE = Idle

    Static isRunning As Boolean
    If isRunning = True Then
        End
    Else
        isRunning = True

        With ActivePresentation
            ActiveWindow.ViewType = ppViewTitleMaster
            With .TitleMaster
                For i = 1 To .Shapes.Count
                    For j = 1 To .Shapes(i).Tags.Count
                        If .Shapes(i).Tags.Name(j) =
"TITLEMASTERPICTURE" Then
                            .Shapes(i).Delete
                            'Now reset the shape counter
                            lShapeCount =
ActivePresentation.TitleMaster­.Shapes.Count
                        End If
                    Next j
                Next i
            End With
        End With
        CommandBars("Insert").Controls­("Picture").Controls("From
File...").Execute

        Do While (ActivePresentation.TitleMaste­r.Shapes.Count =
lShapeCount)
            ' Suspend program execution for 1/5 second (500
milliseconds)
            iTimeCounter = iTimeCounter + 1
            Sleep 500
            If iTimeCounter > 2 Then
                ActiveWindow.ViewType = strViewType
                'The user canceled the dialog
                Exit Do
            ElseIf ActivePresentation.TitleMaster­.Shapes.Count <>
lShapeCount Then
                Exit Do
            Else
            End If '
            ' Very crucial else the display won't refresh itself
            DoEvents
        Loop

        isRunning = False
        'Now capture the Cancel button click and exit
        If ActivePresentation.TitleMaster­.Shapes.Count = lShapeCount
Then
            Exit Sub
        Else
            'continue
        End If
        With ActivePresentation.TitleMaster­.Shapes(lShapeCount + 1)
            .Tags.Add "TitleMasterPicture", "Present"
            'Next line out in case heights of pictures vary
            '.LockAspectRatio = false
            .Top = 0
            .Left = 0
            'Next line out in case heights of pictures vary
            '.Height = 420
            .Width = 720.66
            .LockAspectRatio = True
        End With
        ActiveWindow.ViewType = strViewType
        End
    End If
    Exit Sub
errorhandler:
    MsgBox Error
End Sub

Brian Reilly, PowerPoint MVP

Brian Reilly, PowerPoint MVP

On Wed, 2 Mar 2005 01:39:03 -0800, Jackie
<Jackie@discussions.microsoft.com> wrote:

>Morning all
>
>Can anyone help ... please.
>
>In Word you can show the Microsoft Dialog boxes (ie
>Dialogs(wdDialogInsertPicture).Show) and wondered if the same options were
>available in PowerPoint. I would like to show the Insert Picture dialog box
>but cannot seem to find a way of doing this. The only dialog boxes available
>seem to be "Save as", "Open" etc.
>
>Many thanks
>Jackie



Relevant Pages

  • Re: Print Preview !!!
    ... Visio Development Blog ... Public Sub New ... Dim temporaryShape As Microsoft.Office.Interop.Visio.Shape ... ' picture is the size of the page. ...
    (microsoft.public.visio.developer)
  • Re: Find path to outlook.exe
    ... an API to get it may be a slight bit more reliable. ... "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _ ... Public Function fGetOutlookEXE() As String ... Dim RetVal As Long ...
    (microsoft.public.access.modulesdaovba)
  • Re: Find path to outlook.exe
    ... "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _ ... Public Function fGetOutlookEXE() As String ... Dim RetVal As Long ... this API apparently can take version specific arguments as ...
    (microsoft.public.access.modulesdaovba)
  • Re: Find path to outlook.exe
    ... Public Function fGetOutlookExe() As String ... Dim RetVal As Long ... Move the API module into the Form's module instead of its own. ...
    (microsoft.public.access.modulesdaovba)
  • RE: Programatically insert pictures into a table field
    ... achieve was a high level of evidence integrity, ... If you have a picture control on a form or report, ... The class object is defined with Get & Let properties as well as ... Dim rstCheques As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)