Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preserving a Dialog object (Word 2000)

    [Edited by Rory to remove unnecessary scrolling]

    I have need to solicit settings from an end-user and at a later time re-use the settings for a series of operations. I had thought to preserve the dialog object, as the code below shows, but the Help files are quite clear that the dialogs collection is read-only.

    I can preserve each item from the dialog (.Font, .Format etc.) in Long or String variables, but it seems to me that there ought to be a generic way of grabbing the loaded dialog as an object and stashing it away somewhere as an object, drawing on its constituent parts as required. For example, later on I may need only the .Font.

    I essayed first with a Dim as dialog, then with a variant, then an object, then as untyped, each attempt meets with failure.

    What have I failed to understand here? I can see that I can't store a value back into the dialogs collection, but why can't I take something from the dialogs collection and stash it away in a generic format?

    <pre>Sub TEST()
    ' The Dialog object is a member of the Dialogs collection.
    ' The Dialogs collection contains all the built-in dialog boxes in Word.
    ' You cannot create a new built-in dialog box or add one to the Dialogs collection.
    Dim dlg As Variant
    ' Dim dlgSaved As Dialog
    ' Dim dlgSaved As Variant
    ' Dim dlgSaved As Object
    Dim dlgSaved
    With Dialogs(wdDialogTableAutoFormat)
    If .Display = -1 Then
    Set dlgSaved = dlg
    MsgBox .Format
    Else
    End If
    End With
    With dlgSaved
    .Show ' Run time error '91'
    End With
    End Sub</pre>


  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,873
    Thanks
    0
    Thanked 79 Times in 75 Posts

    Re: Preserving a Dialog object (Word 2000)

    this is untested but what about something like:
    <pre>Sub TEST()
    ' The Dialog object is a member of the Dialogs collection.
    ' The Dialogs collection contains all the built-in dialog boxes in Word.
    ' You cannot create a new built-in dialog box or add one to the Dialogs collection.
    Dim dlg As Variant
    ' Dim dlgSaved As Dialog
    ' Dim dlgSaved As Variant
    ' Dim dlgSaved As Object
    Dim dlgSaved
    Set dlg = Dialogs(wdDialogTableAutoFormat)
    With dlg
    If .Display = -1 Then
    MsgBox .Format
    Else
    End If
    End With
    With dlg
    .Show ' Run time error '91'
    End With
    End Sub
    </pre>

    Regards,
    Rory
    Microsoft MVP - Excel.

  4. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preserving a Dialog object (Word 2000)

    Perfect. Thanks!
    It seems that I can save the dlg created as variant, buyt can't assign it to another variable.<pre> Public dlg As Variant
    Sub TEST2()
    ' The Dialog object is a member of the Dialogs collection.
    ' The Dialogs collection contains all the built-in dialog boxes in Word.
    ' You cannot create a new built-in dialog box or add one to the Dialogs collection.

    ' Dim dlgSaved As Dialog
    ' Dim dlgSaved As Variant
    ' Dim dlgSaved As Object
    Dim dlgSaved
    Set dlg = Dialogs(wdDialogTableAutoFormat)
    With dlg
    If .Display = -1 Then
    MsgBox .Format
    Else
    End If
    End With
    End Sub
    Sub test3()
    With dlg
    .Show
    End With
    End Sub
    </pre>


  5. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,873
    Thanks
    0
    Thanked 79 Times in 75 Posts

    Re: Preserving a Dialog object (Word 2000)

    You can - you just hadn't assigned anything to the <code>dlg</code> variable:
    <pre>Sub TEST()
    Dim dlgSaved1 As Dialog
    Dim dlgSaved2 As Dialog
    Set dlgSaved1 = Dialogs(wdDialogTableAutoFormat)
    With dlgSaved1
    If .Display = -1 Then
    MsgBox .Format
    Else
    End If
    End With
    Set dlgSaved2 = dlgSaved1
    Set dlgSaved1 = Nothing
    With dlgSaved2
    .Show
    End With
    Set dlgSaved2 = Nothing
    End Sub
    </pre>


    HTH
    Regards,
    Rory
    Microsoft MVP - Excel.

  6. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preserving a Dialog object (Word 2000)

    [Edited (again!) to break up excessively long lines - Rory]


    Here is an example of what i feel is a cruddy brute-force approach:<pre> Type TableAutoFormat
    lngFormat As Long
    lngBorders As Long
    lngShading As Long
    lngFont As Long
    lngColor As Long
    lngAutoFit As Long
    lngHeadingRows As Long
    lngLastRow As Long
    lngFirstColumn As Long
    lngLastColumn As Long
    End Type
    Sub TEST()
    ' The Dialog object is a member of the Dialogs collection.
    ' The Dialogs collection contains all the built-in dialog boxes in Word.
    ' You cannot create a new built-in dialog box or add one to the Dialogs collection.
    Dim typTableAutoFormat As TableAutoFormat
    Dim dlg As Variant
    With Dialogs(wdDialogTableAutoFormat)
    If .Display = -1 Then
    typTableAutoFormat.lngFormat = .Format
    typTableAutoFormat.lngBorders = .Borders
    typTableAutoFormat.lngShading = .Shading
    typTableAutoFormat.lngFont = .Font
    typTableAutoFormat.lngColor = .Color
    typTableAutoFormat.lngAutoFit = .AutoFit
    typTableAutoFormat.lngHeadingRows = .headingrows
    typTableAutoFormat.lngLastRow = .lastrow
    typTableAutoFormat.lngFirstColumn = .firstcolumn
    typTableAutoFormat.lngLastColumn = .lastcolumn
    Else
    End If
    End With
    '''
    Dim tbl As Table
    For Each tbl In Selection.Tables
    With tbl
    .AutoFormat Format:=typTableAutoFormat.lngFormat, ApplyBorders:= _
    typTableAutoFormat.lngBorders, ApplyShading:=typTableAutoFormat.lngShading, _
    ApplyFont:=typTableAutoFormat.lngFont, ApplyColor:=typTableAutoFormat.lngColor, _
    ApplyHeadingRows:=typTableAutoFormat.lngHeadingRow s, _
    ApplyLastRow:=typTableAutoFormat.lngLastRow, _
    ApplyFirstColumn:=typTableAutoFormat.lngFirstColum n, _
    ApplyLastColumn:=typTableAutoFormat.lngLastColumn, AutoFit:=typTableAutoFormat.lngAutoFit

    End With
    Next tbl
    End Sub</pre>


  7. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preserving a Dialog object (Word 2000)

    Ah Now I see. Thanks.
    Your line " Set dlgSaved1 = Dialogs(wdDialogTableAutoFormat)" shows me where in my original example I should have included a line "set dlg = ..."
    I'm re-assured because I feel that in VBA one ought always be able to save a bundle of information in VBA's own structures, and I was puzzled because in this case I couldn't do it.
    I need to do more work with objects ....
    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •