Doug,
Here is the code. Appreciate your help.
Sub FileSave()
Dim dlg As Dialog, curDoc As Word.Document
Dim SmartFName As String, CurFName As String, sPath As String, iMsg As Integer
' If template or a document that hasn't been saved yet,
' show the FileSaveAs dialog
If ActiveDocument.Type = wdTypeTemplate Or ActiveDocument.Path = "" Then
Set dlg = Dialogs(wdDialogFileSaveAs)
dlg.name = ActiveDocument.name
If dlg.Show = 0 Then Exit Sub 'Cancelled out of dialog
Exit Sub
' Lib1.ValidProcedureDocument checks to ensure that the activedocument
' has the correct document variables
ElseIf Not Lib1.ValidProcedureDocument(Doc:=ActiveDocument) Then
ActiveDocument.Save
Exit Sub
End If
On Error GoTo ErrTrap
Set curDoc = ActiveDocument
sPath = curDoc.Path & "\"
CurFName = curDoc.name
'GetSmartFName derives a filename based on the document variables
SmartFName = Lib1.GetSmartFName(wrdDoc:=curDoc)
If UCase(CurFName) <> UCase(SmartFName) Then
iMsg = MsgBox("Save file with Smart File Name?" & vbCrLf & SmartFName,
vbQuestion + vbYesNo, msgTitle)
If iMsg = vbYes Then
ActiveDocument.SaveAs FileName:=sPath & SmartFName,
FileFormat:=wdFormatDocument
iMsg = MsgBox("Delete old file?" & vbCrLf & CurFName, vbQuestion +
vbYesNo, msgTitle)
If iMsg = vbYes Then
'The following is where the "Access Denied" error is generated
Kill sPath & CurFName
End If
Else
curDoc.Save 'Save with existing non-SmartFName
End If
Else
curDoc.Save 'Already has SmartFName
End If
Set curDoc = Nothing
Exit Sub
ErrTrap:
If Err.Number = 4198 Then 'Canceled from Save Dialog
Exit Sub
Else
MsgBox "Error: " & Err.Description, vbCritical, msgTitle
End If
End Sub