Loading
Word.Tips.Net WordTips (Menu Interface)

Automatically Saving Document Copies on Floppy

Users of older versions of WordPerfect may be familiar with a command that allows you to save a copy of your current document to the A: drive, without modifying the condition of the document or changing where it is normally saved. Thus, if you open C:\My Docs\MyFile.doc, and initiate this command, a copy of the file is made to A:, and the next time you use the Save command, the file is still saved to its normal place on C:.

Word does not include such a feature, and some people think it should. It seems that a natural place for such a command is the Send To submenu available from the File menu. Normally, this submenu includes only a few items, as it is used for native Word commands that allow direct faxing or use of an e-mail connection. Fortunately, it is like any other menu or submenu in Word and can be customized. How to customize menus has been covered extensively in other issues of WordTips.

Since adding to the submenu is rather easy, the problem is coming up with a command to do the actual copy or save to the A: drive. This is where a custom macro comes to the rescue, as there is no native Word command to achieve the desired effect.

One approach is to simply save the current document to the A: drive. The problem with this is that from that point forward, Word thinks the document belongs on the A: drive. The solution is to store the current location of the file, save it to A:, and then save it again, but this time to the original location. The following macro does this in a few simple steps:

Sub FileCopyToA()
    Dim OrName As String
    OrName = ActiveDocument.FullName
    ActiveDocument.SaveAs "A:\" + ActiveDocument.Name
    ActiveDocument.SaveAs OrName
End Sub

There are drawbacks to such a simple approach, however. First (and potentially most important), if you are working on a large file, it may not fit on the A: drive. In that case, the macro will die an ignoble death, and you will need to take the steps to manually recover by resaving your file to its original location. Another fact of life with this macro is that it will overwrite any existing same-name document on the A: drive. Finally, if you didn't want the document saved, but only wanted a snapshot on A:, this macro is not for you.

A somewhat more flexible version of the FileCopyToA macro is DoubleCopy, which prompts the user for a drive before actually making the copy. Unfortunately, it has the same general drawbacks, as well.

Sub DoubleCopy()
    Dim Message As String, Title As String
    Dim Default As String, Drive As String
    Dim ffname as String, fname as String

    On Error GoTo Quit
    Message = "Enter drive letter for document (A, C, D)"
    Title = "Send Document to File"
    Default = "A"

    ' Display message, title, and default value
    Drive = InputBox(Message, Title, Default)
    If Drive > "" Then
        ffname = ActiveDocument.FullName
        fname = Drive & ":\" & ActiveDocument.Name
        ActiveDocument.SaveAs fname
        ActiveDocument.SaveAs ffname
    End If
    Quit:
End Sub

One of the other drawbacks of the approaches presented so far is that they can be slow—very slow. Word is inherently slow in saving a document to a floppy drive. Unless your document is very small, it is faster to save to a hard drive and then use a copy command to copy a file to the floppy. The following macro, SentToDriveA, takes this approach.

Sub SentToDriveA()
    If ActiveDocument.Saved = False Then ActiveDocument.Save
    System.Cursor = wdCursorWait
    OrigLongFileName = ActiveDocument.Name
    OldPath = ActiveDocument.Path & Application.PathSeparator
    If ActiveDocument.Path = "" Then
        MsgBox "Please save this document before sending to drive A:", _
           vbOKOnly, "This Document Not Saved"
    Else
        Documents(ActiveWindow.Caption).Close
        FileCopy OldPath & OrigLongFileName, "a:\" & OrigLongFileName
        Documents.Open FileName:=OldPath & OrigLongFileName
        Application.GoBack
    End If
    System.Cursor = wdCursorNormal
End Sub

The macro first checks to ensure that the current document has been saved somewhere on your hard drive. (In other words, it is not a brand new document.) Then, it closes the document, copies it to A:, and reopens the document. The reason for the closing is that Word will not allow an open document to be copied. Because the document is closed, it is important that this macro be saved in the Normal.Dot template, or in some other global template.

Finally, if you wanted to create a macro that took a "snapshot" of the current document, without actually saving it to your hard drive before making the copy on A:, you would need to duplicate your document and then save the duplicate to A:. Copying an entire document requires a little more effort that simply grabbing the text content and passing it to a new document, however. Word documents are divided up into chunks that represent the main body, headers and footers, footnotes, etc. These are referenced in VBA using StoryRanges with each StoryRange having a StoryType. The following macro copies each of the StoryRanges to a new document and then prompts to save the new document on A:

Public Sub CopyToA()
    Dim docActive As Document
    Dim docNew As Document
    Dim rngActiveDocPart As Range
    Dim rngNewDocPart As Range
    Dim strDocName As String
    Dim strTemplateName As String

    ' reference the current document
    Set docActive = ActiveDocument

    ' get the name of doc and also path/name
    ' of the template it's based-on
    strDocName = docActive.Name
    strTemplateName = docActive.AttachedTemplate.FullName

    ' create a copy document based on same template
    Set docNew = Documents.Add(strTemplateName)

    ' loop to copy each part of the active doc to the new doc
    For Each rngActiveDocPart In docActive.StoryRanges
        ' reference same part
        Set rngNewDocPart = docNew.StoryRanges _
           (rngActiveDocPart.StoryType)
        rngActiveDocPart.Copy
        rngNewDocPart.Paste
    Next rngActiveDocPart

    ' make the new document active
    docNew.Activate

    ' offer to save it on floppy drive A:\
    With Dialogs(wdDialogFileSaveAs)
        .Name = "A:\" & strDocName
        .Show
    End With
End Sub

This final approach could obviously be modified so that the newly created copy document was closed after saving. That way, your original document would be left open an unsaved to disk when the macro was complete.

If all of the techniques described in this tip sound interesting to you, but you don't have a floppy drive on your system, don't despair. You can just as easily use the same macros to save copies to your flash drive, as well. As long as you know the drive letter for the flash drive, just substitute that drive letter for the A: drive designator in the macros. (Works like a charm.)

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1715) applies to Microsoft Word 97, 2000, 2002, and 2003.

Related Tips:

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.