Run time error 4198

R

Richard

Hi

I have a document which is opened from an original & immediately saved to a
new location to preserve the macros (which seem not to be preserved using a
template).

This works fine from the original, & on a number of subsequent openings, but
if emailed to a different location on opening again the dreaded Run time
error seems to appear.

the code I am using is below:

====================================

Private Sub Document_Open()
Dim strMessage As String
Dim strDocPath As String
Dim strNewPath As String


Set aDoc = ActiveDocument
If ActiveDocument.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
End If
Set aDoc = Nothing

Set rngTable = ActiveDocument.Tables(1).Rows(4).Cells(2).Range
strMessage = Left(rngTable.Text, Len(rngTable.Text) - 2)
If strMessage = "Unopened" Then
strDocPath = ActiveDocument.Path
MsgBox "This document needs to be saved now to Sharepoint" & Chr(10) &
"(My Network Places & Folder of your choice)"

On Error Resume Next

Store:
Dialogs(wdDialogFileSaveAs).Show

strNewPath = ActiveDocument.Path
If strDocPath = strNewPath Then
strMessage = MsgBox("You cannot proceed unless the document is
saved" & Chr(10) & "Do you wish to continue (OK) or exit (Cancel)?",
vbOKCancel)
If strMessage = 1 Then
GoTo Store
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
ActiveDocument.Save
ActiveDocument.Close
Quit
End If
End If
End If



Set rngTable = ActiveDocument.Tables(1).Rows(4).Cells(2).Range
rngTable.Text = ""

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
ActiveDocument.Save 'THIS IS THE LINE HIGHLIGHTED WHEN THE ERROR OCCURS

On Error GoTo 0

End Sub

The failure occurs on the 'ActiveDocument.Save' line.
I am at a loss why this should happen, especially as I had 'On error Resume
next' earlier in the code to avoid this happening.

Any ideas anyone?
Thanks for listening!!
 
F

Fumei2 via OfficeKB.com

1. are you using Option Explicit?

2. I am not sure you can declare the start of a sub-routine (Store:) in the
middle of an IF statement.

IF yadda yadda

Store:
IF blah blah THEN
IF hohum THEN
whatever
Else
whatever else
End IF
End IF
End IF


3. You declare and SET aDoc as ActiveDocument, but never use it.

4. You appear to have a Quit instruction...then keep on using Word.

I am having a hard time following what you are doing.

Gerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top