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!!
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!!