Share via

Run-time error '4198'

Anonymous
2011-10-13T14:06:21+00:00

Worthy Word'ies!

I use a sub-routine:

Sub StampAndSave()

        Call Stamp

        ActiveDocument.Save

        ActiveDocument.UndoClear

End Sub

(It timestamps the document, saves it and makes sure the changes cannot be rolled back, because I do use a 'ActiveDocument.Undo 1000' at closing time)

When running it, I get an error message: Run-time error '4198' Command failed. When I press debug, the line "ActiveDocument.Save" is highlighted. Googling this problem hints at it being a bug related to th OS, so I inserted a DoEvents before the line that failed, but that did not work.

Please help (read: HELP!)

BR Peter Hansen

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-10-20T10:21:02+00:00

Hi Peter,

You could first verify the actual save status

If activedocument.Saved= False then

Sub StampAndSave()

        Dim doc As Word.Document

        Set doc = ActiveDocument ' this was move up

        Call Stamp ' try to jump over this line

        DoEvents

        MsgBox "StampAndSave active document is: " & doc.Name

        id doc.saved = Falsse then doc.Save

        doc.UndoClear

        Set doc = Nothing

End Sub

Regards

JY

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-10-20T10:05:00+00:00

    Hi again Jean Yves,

    I corrected the code as you proposed, but the error message still comes up.

    The document is not in in read only, and the problem is the same wheather I save locally on my PC or on the shared drive. I do have anti-virus.

    I actually think I found the problem:

    The appWord_DocumentBeforeSave function catches my manual save and leads to the doc.save in the StampAndSave function.

    BUT: the doc.save saving gets caught AGAIN by the appWord_DocumentBeforeSave function. The file already gets saved once by the first doc.save, so this this causes the file to be saved twice. Somehov, the OS did not free the file, so the secons doc.save fails.

    This leads to the question: how do I prevent the doc.save event from being caught?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-10-16T06:54:49+00:00

    Peter,

    Hi would move upe the assignment of doc var to be  sure of what the active domcument refers to.

    So Is  this correct  :  MsgBox "StampAndSave active document is: " & doc.Name

    Is the doc not in read only

    do you save it locally or on a share drive ?

    Do you have an anti-virus runnning ?

    Sub StampAndSave()

            Dim doc As Word.Document

            Set doc = ActiveDocument ' this was move up

            Call Stamp ' try to jump over this line

            DoEvents

            MsgBox "StampAndSave active document is: " & doc.Name

            doc.Save

            doc.UndoClear

            Set doc = Nothing

    End Sub

    Regards

    JY

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-10-15T22:58:29+00:00

    Hi Jean-Yves,

    I tried both, last was:

    Sub StampAndSave()

            Dim doc As Word.Document

            Call Stamp

            DoEvents

            Set doc = ActiveDocument

            MsgBox "StampAndSave active document is: " & doc.Name

            doc.Save

            doc.UndoClear

            Set doc = Nothing

    End Sub

    It is the doc.Save that fails. I tried to copy everything into a new Word document (has worked in the past on some mysterious problems), but it did not solve the problem.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-10-13T15:15:37+00:00

    Hi,

    I dont know what the Call stamp routine is doing but try this

    Sub StampAndSave()

            Call Stamp

            msgbox "active docment is & activedocument.name

            ActiveDocument.Save

            ActiveDocument.UndoClear

    End Sub

    or

    Sub StampAndSave()

    Dim doc as worddocument

    set doc = activedocument 

           Call Stamp

            msgbox "active docment is & activedocument.name

            doc.Save

            doc.UndoClear

    set doc = Nothing

    End Sub

    Regqrds

    JY

    Was this answer helpful?

    0 comments No comments