How to copy an open file using VBA

Article contributed by Dave Rado

The VBA FileCopy statement will not copy files that are open. However, the WordBasic equivalent will (this is what is known as progress!).

Unfortunately, the syntax of WordBasic equivalent is different in Word 97 and Word 2000!

The following works even if the file being copied is open:

If Left$(Application.Version, 1) = "8" Then
    'Word 97
   
WordBasic.CopyFile FileName:="c:\OldDirectory\Temp.doc", _
            Directory:="C:\NewDirectory\Temp.doc"
Else
    'Word 2000 and above
    WordBasic.CopyFileA FileName:="c:\OldDirectory\Temp.doc", _
            Directory:="C:\NewDirectory\Temp.doc"
 End If

Why did they add the extra A in Word 2000? Why does it always rain at weekends but never during the week? Microsoft works in mysterious ways, their wonders to perform. Maybe one of the developers had a hangover the day that change was made.

See also:
How to create a copy of an open document
Useful WordBasic commands that have no VBA equivalent


Click to view Terms of Use page

Click to view Disclaimer page