Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2025, 05:30 PM
Dr. Rick Dr. Rick is offline Macro to warn about removeable media save? Windows 10 Macro to warn about removeable media save? Office 2010
Advanced Beginner
Macro to warn about removeable media save?
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 45
Dr. Rick is on a distinguished road
Unhappy Macro to warn about removeable media save?

This may need to be moved to a different section. I thought there used to be a section called "Macros," but there doesn't seem to be one now.



Having very recently learned that Word doesn’t handle detachable media well, I am looking for a macro (or an add-on of some sort) that would be constantly on the lookout for my saving a Word file to any drive other than “C:” and warn me about this problem before I save the current file to anywhere other than my main (or whatever the proper term is) drive. I don’t care how polished or elegant it might be, but only that it work. I am so used to saving my work to thumb drives and SD cards that it will take some doing to break this habit, and this is what I’m looking for in this macro. If there’s already a commercial program that can do this, let me know. I’m not averse to spending some money to prevent my files from turning into gibberish.

Any help would be greatly appreciated. Thanks in advance.
Reply With Quote
  #2  
Old 10-31-2025, 12:30 PM
Charles Kenyon Charles Kenyon is offline Macro to warn about removeable media save? Windows 11 Macro to warn about removeable media save? Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,589
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Moved from https://www.msofficeforums.com/word/...w-appears.html.

I moved this to the Word vba forum.
I do not know of such a macro.
I think the macro would need to know the drive letter(s) of your hard drive(s) and give a warning when saving to any other location.

In the past, I used the following as a warning:

Code:
Sub AutoOpen() ' floppy warning - to go in files stored on a floppy drive
    MsgBox prompt:="This should not be used from a floppy disk. If it is not" & vbCrLf _
                   & "on your hard drive, close it now without saving changes.", _
           title:="Hard disk use only.", _
           Buttons:=vbExclamation
 End Sub

Again, with care, you can use external drives, but you need to be aware of what you are doing.
(It used to be a problem of insufficient space but that is seldom a problem with external media today; but, it could be.)
Reply With Quote
  #3  
Old 10-31-2025, 02:37 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

You could add the following code to the 'ThisDocument' module of Word's Normal Template (or whatever other template you're using). It will warn you if the document you've just opened is not on a fixed or network drive.
Code:
Private Sub Document_Open()
Dim DrvNm As String, DocNm As String, FSO As Object, Drv As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
DrvNm = Left(ActiveDocument.Path, 1): DocNm = Split(ActiveDocument.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
If you already have a Document_Open sub, simply add the code between the first and last lines to it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 10-31-2025, 05:24 PM
Charles Kenyon Charles Kenyon is offline Macro to warn about removeable media save? Windows 11 Macro to warn about removeable media save? Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,589
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Hi Paul,


My example macro was nowhere near close, I know.
What is needed, though is to intercept the save, in all of its forms, not the open.
Reply With Quote
  #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
  #6  
Old 11-01-2025, 05:00 AM
Dr. Rick Dr. Rick is offline Macro to warn about removeable media save? Windows 10 Macro to warn about removeable media save? Office 2010
Advanced Beginner
Macro to warn about removeable media save?
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 45
Dr. Rick is on a distinguished road
Default

Thanks to both Charles K. and Paul E.


I'm afraid this is one of those cases where the solution is so far above the head of the poser of the question (me) that I wouldn't know where to begin. The fact that (a) no ready-made macro or third-party software exists to address this issue and (b) that Microsoft apparently allows this situation to persist are both puzzling to me.


I have just enough understanding to realize (in retrospect) how complex it might be to intercept a save before it happens and warn the user. According to my limited understanding, there is not a problem copying files to and from detachable media when Windows does so, but only when Word is involved. You (both, I think) suggest that this could stem from the user not removing the drives at the wrong time, and I'm sure this could be true. Personally, I've been quite careful about "safely removing hardware and ejecting media." Am I sure it's 100%? Well...even if it's only 99.9%--


Although my preference would be to have Word be aware of which removable drives are available and specifically warn me whenever I was saving to a removable drive, I would be almost as happy just having a warning screen pop up with every attempted save (or -save as) that says something like "Are you saving to a re-moveable drive? If so, consider NOT doing so." (or similar wording). This would give me time to get used to the idea of "acting like removable media don't exist".


I guess I could put a scotch-taped message on my laptop to warn me (yeah, this is meant to be funny)


Apologies for the length of this post.
Reply With Quote
  #7  
Old 11-01-2025, 01:22 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

Implementing the first solution I posted is easy enough:
1. Start Word and open a blank document.
2. Press Alt-F-11. In the top left corner you should see something like the first image.
3. Click on 'Microsoft Word Objects' to expand it, so that you see the second image.
4. Click on 'This Document'. You now see something like the third image.
5. Simply copy & paste the code from post #3 into the window below '(General)'.
Done. You will now be alerted whenever you open a document on removable media.
Attached Images
File Type: png VBE1.png (15.5 KB, 9 views)
File Type: png VBE2.png (16.2 KB, 9 views)
File Type: png VBE3.png (45.5 KB, 9 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



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 08:03 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