![]() |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.) |
|
#3
|
||||
|
||||
|
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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 • 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] |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to save as pdf with ability to choose save as folder
|
rvessio | Word VBA | 4 | 07-25-2016 12:37 PM |
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 |