+ Reply to Thread
Results 1 to 3 of 3

Error message appears ("Run-time error '4198'...) when clicking Cancel in Save As window

  1. #1
    Registered User
    Join Date
    01-22-2016
    Location
    Albany, NY
    MS-Off Ver
    2010
    Posts
    31

    Error message appears ("Run-time error '4198'...) when clicking Cancel in Save As window

    I'm very new to Excel and I have a problem I'm struggling with in VB. I have a document object variable that references a Word document that is generated in VB script which has text added to it dynamically etc. When I execute a Close (i.e. objDocument.Close) before the document is saved, a message displays asking the user whether they want to save or not. If they choose Save and provide a valid file name and path, the document saves successfully. But if they choose "Cancel", a message box appears displaying "Run-time error '4198': Command failed".

    Does anyone have any idea why this message appears? I'm not sure what I may be doing wrong.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Error message appears ("Run-time error '4198'...) when clicking Cancel in Save As wind

    You can ask first, so that it will be less likely that they cancel, and handle the error when it occurs

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-22-2016
    Location
    Albany, NY
    MS-Off Ver
    2010
    Posts
    31

    Re: Error message appears ("Run-time error '4198'...) when clicking Cancel in Save As wind

    Thanks for taking the time to respond. Using the On Error command has given me some ideas. When I ask the user if they want to save using the msgbox you suggested and they choose yes, it displays the Save As window. But if they happen to choose Cancel, when oWord.Application.Quit is executed, another message box appears asking the user: "Do you want to save changes you made to Document2?" I believe this occurs because the Saved property of the objdoc is False.

    I altered the logic a bit and it seems to work for the moment:

    ' If an error is generated when the user closes the document, ignore it and resume.
    On Error Resume Next
    objDoc.Close True
    ' If objDoc is empty, this implies the Close method above successfully closed the document and objDoc.Saved will have been set to True. However, if the Close had failed (user clicked Cancel), objDoc will not be empty as the document is still open and objDoc.Saved will be equal to False. In this case, set Saved to True so that the Application.Quit method doesn't prompt the user again to save when it attempts to close.
    If Not IsEmpty(objDoc) Then
    objDoc.Saved = True
    End If

    objWord.Application.Quit
    Set objWord = Nothing


    Hope this makes sense.
    Thanks again for your help!
    Last edited by JaguerRhye; 02-03-2016 at 12:26 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Im getting a run time error "438" message on my Apple Mac Pro
    By Frank Yaconetti in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2015, 04:09 AM
  2. [SOLVED] .SaveAs error for Word (Error 4198: Command Failed)
    By hoboken in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2015, 06:53 PM
  3. Replies: 1
    Last Post: 10-31-2014, 08:03 AM
  4. [SOLVED] Getting file name "False.xlsm" when I click 'Cancel' on the 'Save as' window
    By LewisM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2014, 01:04 PM
  5. [SOLVED] Error while closing / cancel search window
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2014, 02:24 PM
  6. [SOLVED] Merge Macro error when clicking Cancel
    By bcas77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2013, 01:08 PM
  7. [SOLVED] erroneous "save changes?" message appears
    By crimsonkng in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-16-2008, 12:22 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1