Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Macro Error Message

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Me - 25 Oct 2005 19:21 GMT
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
Doug Robbins - Word MVP - 25 Oct 2005 21:03 GMT
The macro appears to have been originally written in Word.Basic and been
converted by running it in Visual Basic.  It should be rewritten in Visual
Basic.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I recently inherited a Word document that is giving me the following error
> when I first run a customized save macro:
[quoted text clipped - 124 lines]
> bye:
> End Sub
Me - 25 Oct 2005 21:41 GMT
Is the a converter app available?  No one in my area knows anything about
Visual Basic.

> The macro appears to have been originally written in Word.Basic and been
> converted by running it in Visual Basic.  It should be rewritten in Visual
[quoted text clipped - 128 lines]
> > bye:
> > End Sub
Tony Jollans - 25 Oct 2005 23:01 GMT
I agree it should probably be converted but it should work.

The answer to your question is in the comments in the code ...

' 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.

--
Enjoy,
Tony

> The macro appears to have been originally written in Word.Basic and been
> converted by running it in Visual Basic.  It should be rewritten in Visual
[quoted text clipped - 136 lines]
> > bye:
> > End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.