Results 1 to 13 of 13
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    I can't seem to get the following to work properly. I'm running it from the template attached to oDoc, trying to save newDoc:
    <code>
    Documents(newDoc).Activate
    With Dialogs(wdDialogFileSaveAs)
    .Name = strName
    If .Show <> 0 Then
    oDoc.Close (wdDoNotSaveChanges)
    Else
    Windows(oDoc).Visible = True
    End If

    End With
    </code>
    The code works OK, except when the filename already exists, in which case I can press "Save" all day, but not get the prompt to ask if I want to overwrite. Save As works fine from the File menu in newDoc, or from the dialog, if I tender a non-existent filename. Any ideas on how to get the overwrite prompt to appear?

    thanks
    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Seems buggy. You can get around it by using .Display and testing yourself:

    With Dialogs(wdDialogFileSaveAs)
    .Name = strName
    If .Display = -1 Then
    If .Name = strName Then
    If MsgBox("Do you want to overwrite the existing file?", _
    vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then
    Exit Sub
    End If
    End If
    .Execute
    End If
    End With

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Thanks Hans. I'm glad it's not just me then. However, I can't get your code to work either. The dialog just seems to hang on clicking "Save". The only way to exit is with a Close or Cancel. ???

    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    There seem to be differences between versions of Word here. Perhaps your version does put up an overwrite prompt, but it's hidden behind another window, or invisible.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    I think I had a problem like this once, but I can't remember what I did to work around it. Maybe a loop along these lines?

    do
    if dialog.display <> cancel
    if dir(filename) = vbnullstring then 'unique name
    save;close;exit do
    else
    select case msgbox("overwrite?", vbYesNoCancel)
    Case vbYes
    save;close;exit do
    Case vbNo
    'loop and redisplay dialog
    Case vbCancel
    exit whatever
    end select
    end if
    else
    exit whatever
    end if
    loop

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    It seems buggy alright. This morning, starting with a "clean slate", the code works as expected. Last night, I was working with the template document open, an (possibly) several instances of Word running. I'll fiddle further, but I suspect that you might be right in suggesting that the overwrite dialog might have been appearing somewhere obscured. I noticed in by code, that I'd been playing around with window visibility and minimizing, so I may have been trying to force it into the open.

    Alan

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Thanks Jefferson. It appears to be working today, since the moon has entered a new phase and Venus and Saturn are in alignment. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I was playing with something similar to your method, but would need to use a homegrown "dialog", since to "Save" button on the built-in SaveAs is rendered ineffective when the problem occurs. Considering the apparent bug, it's a pity the plain old SaveAs command doesn't carry an optional overwrite prompt parameter.

    Alan

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Having not accounted for the cusp of Mercury whilst Jupiter was entering the Seventh House, the same code that worked yesterday failed today. Having gotten thoroughly fed up with this and (at least) two other buggy Word features, I began to hunt elsewhere. I dismissed some custom ActiveX controls and API alternatives as being "too much" to solve such a simple problem.

    But then, fiddling in XL, I found a "native" method, which was more consistently reliable, but not "bulletproof". It's the GetSaveAsFilename function, which is not available in Word, but uses a dialog identical in appearance to the problematic wdDialogFileSaveAs dialog. Sorting through a few more idiosyncracies, I think I've finally cobbled together something that works:

    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black><font color=blue>Case</font color=blue> vbNo
    ChDrive strPath <font color=448800>' These two lines must appear immediately before GetSaveAsFilename _
    or it's quite likely the path will revert to the default.</font color=448800>
    ChDir (strPath) <font color=448800>' No use without changing drive if strPath is on a different drive!!</font color=448800>

    <font color=448800>' InitialFilename must include drive and full path, or the Save In: folder will _
    revert to the default.</font color=448800>
    strNewName = Excel.Application.GetSaveAsFilename( _
    InitialFilename:=strPath & Application.PathSeparator & "*Excess Collection.doc", _
    FileFilter:="Text Files (*.txt), *.txt, Word Documents (*.doc), *.doc", _
    FilterIndex:="2", _
    Title:="Release Documents")
    <font color=blue>If</font color=blue> strNewName = <font color=blue>False</font color=blue> <font color=blue>Then</font color=blue> <font color=blue>Exit</font color=blue> <font color=blue>Sub</font color=blue>
    </font color=black></code></div hiblock>

    This seems to deal with the problematic vbNo case in the previous thread. It requires a reference to the Excel 9.0 Object Library in the VBA project. Hope it's useful to somebody else.

    Alan

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Starting Excel consumes lots of resources. An API solution is lightweight and doesn't need to be complicated. In the attached document, it has been encapsulated in a class module plus a standard module declaring some constants. You can copy those into your project.
    Attached Files Attached Files

  10. #10
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Thanks Hans. I'll certainly take a look at yours. I did fail to mention, however, that the Word docs in question were being generated via automation from a running XL, so I didn't really consider the extra overheads in other scenarios.

    Alan

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    Hans,

    This is a very nice adaptation of wrapping the standard API methods into a class. Is it an orignal? I now like this as a solution, especially since I can easily bundle it in a add-in, common to the many document types dealt with in this project. I came across a related article on Changing button captions in GetOpenFileName dialog, which I might also try.

    I seem to recall you pointing to or explaining an easy method to display a "Browse for Folder" dialog, but can't seem to find the post. I have an API solution, but I think maybe yours used WSH ??? Do you recall the post?

    Alan

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    I wrote the class module myself, based on an example provided by Microsoft in a standard module for use in Access, so it can hardly be called original.

    See <post#=271,140>post 271,140</post: > for <!profile=Don Ceraso>Don Ceraso<!/profile>'s GetFolder function.

  13. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prompt with SavaAs dialog (2000 sp-3/ 98SE)

    > so it can hardly be called original.
    Your definition of "original" seems to be far too stringent. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Yes <img src=/S/yep.gif border=0 alt=yep width=15 height=15> that was the code I was thinking of. That thread and those linked to it, is quite a resource in itself.

    cheers <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Alan

Posting Permissions

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