Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 10-31-2025, 08:06 PM
macropod's Avatar
macropod macropod is offline Macro to warn about removeable media save? Windows 10 Macro to warn about removeable media save? 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to warn about removeable media save? Macro to save as pdf with ability to choose save as folder rvessio Word VBA 4 07-25-2016 12:37 PM
Macro to warn about removeable media save? Macro: How to get this macro to save to a specific location LOUF Word VBA 1 12-07-2015 06:47 PM
Windows Media Player Boo Excel Programming 0 04-28-2013 06:51 AM
Powerpoint save as WMV but media doesnt work. hooney PowerPoint 0 02-21-2013 09:45 PM
Warn user/viewers if Font is not installed. Rehnn Word 0 10-01-2009 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft