M
Me
I recently inherited a Word document that is giving me the following error
when I first run a customized save macro:
"Word cannot copy a file to itself. G:\.....xxxxxxxxxx"
Now, if I Ok out of that error and rerun the macro, it runs without incident.
What is the probable cause of this error? I'm not too familiar with macro
coding, so I don't know what to really look for.
Any ideas on how to alleviate this error would be greatly appreciated.
Thank you.
BTW, I'm using Word 2003 on W2K.
The error is below:
Sub SODRSave()
'******** _LASODR.DOT "SODRSave" MSWord Macro ********************
'** last rev. 05/23/2003 **
'*****************************************************************
Dim locfolderprefix$
Dim netfolderprefix$
Dim regionprefix$
Dim fileopenpointer$
Dim a$
Dim namefile$
Dim b$
Dim netfolderyear$
Dim netfoldermonth$
Dim netfolder$
Dim button
'****** THESE VARIABLES MUST BE MANUALLY ASSIGNED BY THE USER ******
locfolderprefix$ = "C:\_T&D Operations\Reports\Lancaster" ' C: drive save
path prefix.
netfolderprefix$ = "G:\ENGRDSGN\T&D Operations\Reports\Lancaster" ' Network
drive save path prefix.
regionprefix$ = "LA" ' Two character region filename prefix.
' Note: Year and Month sub-folders are automatically created.
'*******************************************************************
'
fileopenpointer$ = locfolderprefix$ ' "File+Open" command to point to this
folder.
'
'******
cksaveneeded:
' If WordBasic.IsDocumentDirty() = 0 Then GoTo bye
a$ = WordBasic.[FileName$]()
If LCase(WordBasic.[Left$](WordBasic.[Right$](a$, 16), 2)) <>
LCase(regionprefix$) Then
button = WordBasic.MsgBox("Not a valid SODR file name." + Chr(13) +
"Must be in the form of '" + regionprefix$ + "2003_02_30.DOC '", " SODR bad
filename ", 0)
GoTo bye
End If
'
cdrivesave:
'WordBasic.FileSave
namefile$ = WordBasic.[Right$](a$, 29)
WordBasic.FileSaveAs Name:=locfolderprefix$ + "\" + namefile$
'
createnetfoldersavename:
b$ = WordBasic.[Left$](WordBasic.[Right$](a$, 14), 4)
netfolderyear$ = b$
netfoldermonth$ = b$ + "_" + WordBasic.[Left$](WordBasic.[Right$](a$, 9), 2)
netfolder$ = netfolderprefix$ + "\" + netfolderyear$ + "\" + netfoldermonth$
'
WordBasic.PrintStatusBar "Saving to Network Drive. PLEASE WAIT. I'll let
you know what happened soon."
WordBasic.WaitCursor 1
On Error GoTo ErrorHandler
'
checknetfolderyear:
WordBasic.ChDir netfolderprefix$
On Error Resume Next
WordBasic.MkDir netfolderyear$
'
checknetfoldermonth:
WordBasic.ChDir netfolderyear$
On Error Resume Next
WordBasic.MkDir netfoldermonth$
'
netdrivesave:
WordBasic.CopyFile FileName:=a$, Directory:=netfolder$
' When using SODRSave macro to save the file opened from the G: drive,
' the file will not save to the G: drive the first time
' and a message will indicate cannot copy to itself.
' The file will save to the G: drive on subsequent tries.
' Because after the file is saved to the C: drive on the first try,
' the open file becomes the one saved to C: drive.
GoTo done
'
ErrorHandler:
button = WordBasic.MsgBox("File successfully saved to: " + Chr(13) + a$ +
Chr(13) + Chr(13) + "Unable to save to Network drive: " + Chr(13) +
netfolder$, " SODR path unavailable ", 0)
button = WordBasic.MsgBox("Network may be unavailable at this time." +
Chr(13) + "Use 'Save' command from File menu until the network connection is
restored.", " SODR path unavailable ", 0)
Err = 0
GoTo fileopenpointer
'
done:
WordBasic.PrintStatusBar "Save completed."
'
fileopenpointer:
' This section is to make the File menu + Open command in Word
' point to the folder specified in fileopenpointer$, normally on the C: drive.
' Otherwise it would point to the last save path, which is a network drive.
' This is to help avoid opening a file manually from a wrong location by
mistake.
On Error Resume Next
WordBasic.ChDir fileopenpointer$ ' "File+Open" will now point to this folder.
GoTo bye
'
bye:
End Sub
when I first run a customized save macro:
"Word cannot copy a file to itself. G:\.....xxxxxxxxxx"
Now, if I Ok out of that error and rerun the macro, it runs without incident.
What is the probable cause of this error? I'm not too familiar with macro
coding, so I don't know what to really look for.
Any ideas on how to alleviate this error would be greatly appreciated.
Thank you.
BTW, I'm using Word 2003 on W2K.
The error is below:
Sub SODRSave()
'******** _LASODR.DOT "SODRSave" MSWord Macro ********************
'** last rev. 05/23/2003 **
'*****************************************************************
Dim locfolderprefix$
Dim netfolderprefix$
Dim regionprefix$
Dim fileopenpointer$
Dim a$
Dim namefile$
Dim b$
Dim netfolderyear$
Dim netfoldermonth$
Dim netfolder$
Dim button
'****** THESE VARIABLES MUST BE MANUALLY ASSIGNED BY THE USER ******
locfolderprefix$ = "C:\_T&D Operations\Reports\Lancaster" ' C: drive save
path prefix.
netfolderprefix$ = "G:\ENGRDSGN\T&D Operations\Reports\Lancaster" ' Network
drive save path prefix.
regionprefix$ = "LA" ' Two character region filename prefix.
' Note: Year and Month sub-folders are automatically created.
'*******************************************************************
'
fileopenpointer$ = locfolderprefix$ ' "File+Open" command to point to this
folder.
'
'******
cksaveneeded:
' If WordBasic.IsDocumentDirty() = 0 Then GoTo bye
a$ = WordBasic.[FileName$]()
If LCase(WordBasic.[Left$](WordBasic.[Right$](a$, 16), 2)) <>
LCase(regionprefix$) Then
button = WordBasic.MsgBox("Not a valid SODR file name." + Chr(13) +
"Must be in the form of '" + regionprefix$ + "2003_02_30.DOC '", " SODR bad
filename ", 0)
GoTo bye
End If
'
cdrivesave:
'WordBasic.FileSave
namefile$ = WordBasic.[Right$](a$, 29)
WordBasic.FileSaveAs Name:=locfolderprefix$ + "\" + namefile$
'
createnetfoldersavename:
b$ = WordBasic.[Left$](WordBasic.[Right$](a$, 14), 4)
netfolderyear$ = b$
netfoldermonth$ = b$ + "_" + WordBasic.[Left$](WordBasic.[Right$](a$, 9), 2)
netfolder$ = netfolderprefix$ + "\" + netfolderyear$ + "\" + netfoldermonth$
'
WordBasic.PrintStatusBar "Saving to Network Drive. PLEASE WAIT. I'll let
you know what happened soon."
WordBasic.WaitCursor 1
On Error GoTo ErrorHandler
'
checknetfolderyear:
WordBasic.ChDir netfolderprefix$
On Error Resume Next
WordBasic.MkDir netfolderyear$
'
checknetfoldermonth:
WordBasic.ChDir netfolderyear$
On Error Resume Next
WordBasic.MkDir netfoldermonth$
'
netdrivesave:
WordBasic.CopyFile FileName:=a$, Directory:=netfolder$
' When using SODRSave macro to save the file opened from the G: drive,
' the file will not save to the G: drive the first time
' and a message will indicate cannot copy to itself.
' The file will save to the G: drive on subsequent tries.
' Because after the file is saved to the C: drive on the first try,
' the open file becomes the one saved to C: drive.
GoTo done
'
ErrorHandler:
button = WordBasic.MsgBox("File successfully saved to: " + Chr(13) + a$ +
Chr(13) + Chr(13) + "Unable to save to Network drive: " + Chr(13) +
netfolder$, " SODR path unavailable ", 0)
button = WordBasic.MsgBox("Network may be unavailable at this time." +
Chr(13) + "Use 'Save' command from File menu until the network connection is
restored.", " SODR path unavailable ", 0)
Err = 0
GoTo fileopenpointer
'
done:
WordBasic.PrintStatusBar "Save completed."
'
fileopenpointer:
' This section is to make the File menu + Open command in Word
' point to the folder specified in fileopenpointer$, normally on the C: drive.
' Otherwise it would point to the last save path, which is a network drive.
' This is to help avoid opening a file manually from a wrong location by
mistake.
On Error Resume Next
WordBasic.ChDir fileopenpointer$ ' "File+Open" will now point to this folder.
GoTo bye
'
bye:
End Sub