Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Save As Dialog (word 2000 )

    When i try to save a document using the save As dialog in Word, I want to be able to close the current document if the "Cancel" button is clicked. How can i do this?

    Thanks.

  2. #2
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Save As Dialog (word 2000 )

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> su1234

    OK so if I cancel the SaveAs operation, you want the code to close the document and not save it, save it with the same name and location, or save it to a default location with a default name?

    You ought to be able to trap the Save event and then do what you want if it is canceled.

    I tried looking for the SaveAs event in Word, but did not find any events other than New, Close and Open, for the Document object?

    In MS-Excel you can do the following:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Cancel = True Then
    ThisWorkbook.Close SaveChanges:=False
    End If
    End Sub

    The vakues for the SaveChanges are:

    True: Saves the changes to the workbook. If there is not yet a file name associated with the workbook, then FileName is used. If FileName is omitted, the user is asked to supply a file name.

    False: Does not save the changes to this file.

    Omitted: Displays a dialog box asking the user whether or not to save changes.


    HTH

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  3. #3
    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: Save As Dialog (word 2000 )

    <P ID="edit" class=small>(Edited by jscher2000 on 05-Sep-03 23:18. Sorry, you don't have to .Execute after you .Show, you .Execute if you only .Display)</P>When you present the SaveAs dialog programmatically, you get back 0 for cancel or -1 for OK (or Save, whatever that button says, you know what I mean):

    <pre>With Dialogs(wdDialogFileSaveAs)
    If .Show = -1 Then
    'user saved
    Else
    'user canceled
    ActiveDocument.Close savechanges:=wdDoNotSaveChanges
    End If
    End With</pre>

    Most of the Word dialogs work this way, except the ones that stay open for repeat business rather than executing upon closing.

  4. #4
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save As Dialog (word 2000 )

    Thanks this worked for me... But here is a scenario that is driving me crazy. I have a.doc already open. When i get to the .Show i prepopulate .Name : = "1". So i keep clicking the Save button and it does not do anything, But when i Cancel out of the Dialog Box, I see an error message. I want to be able to display the error message. Here is the code i have. Also it is at the .execute command that the error message is displayed but it hides behind the SaveAs dialog box.. SO please let me know what i am doing wrong.

    With Dialogs(wdDialogFileSaveAs)
    Dim li_button As Integer
    .Name = "C:" & ll_cnt
    .Execute
    li_button = .Display

    ' if the cancel button is clicked
    If li_button = 0 Then
    Cancel = True
    'Documents(rs_docname).Close SaveChanges:=wdDoNotSaveChanges
    Dim ll_count As Long
    ll_count = Documents.Count
    If ll_count = 1 Then
    Word.Application.Quit SaveChanges:=wdDoNotSaveChanges
    Else
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    End If
    End If
    ' if save button is clicked, send control to top of the document
    If li_button = -1 Then
    docNew.Range(0, 0).Select
    Selection.HomeKey Unit:=wdStory
    End If
    End With

    Thanks....

  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: Save As Dialog (word 2000 )

    First, why are you setting Cancel = True? Are you using this code inside an event procedure? I can't help you if you are; I never handle Save calls that way ('though perhaps I should learn how).

    My code was designed as an alternative to that, a way to directly intercept the FileSaveAs command if called directly through the UI (menu or toolbar or keyboard shortcut). (You need separate procedures to handle FileSave and FileClose and, I suppose, FileExit, to cover all the bases.)

    Now, in your code, you should not call .Execute before you .Display. The .Execute method is used to effectuate the choice the user made while the dialog was displayed (i.e., Save or Cancel). This should solve some of the problem.

Posting Permissions

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