Attribute VB_Name = "DeleteOrRenameActiveDocument"
'Copyright: Zoran Vučić, 2001.
Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Type SHFILEOPSTRUCT
  hwnd As Long
  wFunc As Long
  pFrom As String
  pTo As String
  fFlags As Integer
  fAnyOperationsAborted As Long
  hNameMappings As Long
  lpszProgressTitle As String 'only used if FOF_SIMPLEPROGRESS
End Type

Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FO_MOVE = &H1
Const FO_RENAME = &H4
Const FOF_ALLOWUNDO = &H40
Const FOF_FILESONLY = &H80
Const FOF_MULTIDESTFILES = &H1
Const FOF_NOCONFIRMATION = &H10
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_NO_CONNECTED_ELEMENTS = &H1000
Const FOF_NOCOPYSECURITYATTRIBS = &H800
Const FOF_NOERRORUI = &H400
Const FOF_RENAMEONCOLLISION = &H8
Const FOF_SILENT = &H4
Const FOF_SIMPLEPROGRESS = &H100
Const FOF_WANTMAPPINGHANDLE = &H20
Const FOF_WANTNUKEWARNING = &H2000

Dim fos As SHFILEOPSTRUCT

Public Function MoveToRecycleBin(fileFullName) As Long
  With fos
    .hwnd = 0
    .wFunc = FO_DELETE
    .pFrom = fileFullName & vbNullChar & vbNullChar
    .pTo = vbNullChar & vbNullChar
    .fFlags = FOF_ALLOWUNDO
    '.fAnyOperationsAborted = 0
    '.hNameMappings = 0
    '.lpszProgressTitle = 0 'vbNullChar
  End With
MoveToRecycleBin = SHFileOperation(fos)
End Function


'Copyright: Zoran Vučić, 2003.
Sub DeleteActiveDocument()
  Dim a$, b$, poruka$
  Dim foResult As Long
  If Application.Documents.Count = 0 Then
    Exit Sub
  End If
  a$ = ActiveDocument.FullName
  b$ = ActiveDocument.Name
  ActiveDocument.Close
  If Dir(a$) <> "" Then
    foResult = MoveToRecycleBin(a$)
  End If
End Sub

'Copyright: Zoran Vučić, 2009.
Sub RenameActiveDocument()
  Dim a$, b$, poruka$
  Dim foResult As Long
  If Application.Documents.Count = 0 Then
    Exit Sub
  End If
  a$ = ActiveDocument.FullName
  b$ = ActiveDocument.Name
  Dialogs(wdDialogFileSaveAs).Show
  If Dir(a$) <> "" Then
    foResult = MoveToRecycleBin(a$)
  End If
End Sub

