View Single Post
 
Old 10-31-2025, 08:06 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,523
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

One would assume that, given the corruption susceptibility relating to documents on flash drives being opened, I'd have thought a Document_Open macro would suffice. After all, if you've opened one from a fixed disk and you're saving to a flash drive, you're using Save As and I'd expect that's because that's what you intended to do. Intercepting saves is a lot more work, entailing an Application.Event handler, a 'ThisApplication' class module, and a DocumentBeforeSave macro. Even then, it won't trap the first SaveAs of a document on removable media. Still, if that's the route you want to take, in your document template you'll need:

• A standard code module containing:
Code:
Dim wdAppClass As New ThisApplication

Public Sub AutoExec()
Set wdAppClass.wdApp = Word.Application
End Sub
If you already have a standard code module, simply put this code at the top.

• A class module named 'ThisApplication' containing:
Code:
Public WithEvents wdApp As Word.Application

Private Sub wdApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim DrvNm As String, DocNm As String, FSO As Object, Drv As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
DrvNm = Left(Doc.Path, 1): DocNm = Split(Doc.Name, "do")(0)
For Each Drv In FSO.Drives
  Select Case Drv.DriveType
    Case 1 'Removable
      If Drv.DriveLetter = DrvNm Then MsgBox DocNm & " is on Removable Drive " & Drv.DriveLetter: Exit For
    Case 2 'Fixed
    Case 3 'Network
    Case 4 'CD-ROM
      If Drv.DriveLetter = DrvNm Then MsgBox DocNm & " is on CD-ROM " & Drv.DriveLetter: Exit For
    Case 5 'RAM-Disk
      If Drv.DriveLetter = DrvNm Then MsgBox DocNm & " is on RAM-Disk " & Drv.DriveLetter: Exit For
  End Select
Next Drv
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote