Re: Save to Network by Peter
Peter
Wed Feb 18 19:56:35 CST 2004
Hi Jerry
Rather than use Words save method, use the SaveAs, something like this:
Public Sub SaveDocTwice()
Const cAPath As String = "A:\"
Const cNetWorkPath As String = "F:\"
Dim strOriginalFullPath As String
Dim strOriginalPath As String
With ActiveDocument
' Before we do anything make sure that
' the current document has been
' previously saved and is saved to one of the two permisable paths
strOriginalFullPath = .FullName
strOriginalPath = .Path & "\"
If Len(.Path) = 0 Then
MsgBox "The document must have been previously" & _
" saved as it has no name"
Exit Sub
End If
If StrComp(strOriginalPath, cAPath, vbTextCompare) <> 0 And _
StrComp(strOriginalPath, cNetWorkPath, vbTextCompare) <> 0 Then
MsgBox "You cannot save the current document it " & _
" does not use an expected path: " & strOriginalPath
Exit Sub
End If
' keep it smooth for the user
Application.ScreenUpdating = False
' Do it this way so it doesn't matter which document we're using
.SaveAs "C:\" & .Name
.SaveAs "F:\" & .Name
' If the current document is not the original one
' then close this one and reopen the original
If .Path & "\" <> strOriginalPath Then
.Close wdDoNotSaveChanges
Documents.Open strOriginalFullPath
End If
Application.ScreenUpdating = True
End With
End Sub
This code checks that the document you are saving has been previously
saved, because if it hasn't then it doesn't have a name! It then checks
that the docuemnt has been saved to one of the 2 permisable paths, this
ensures that it's one of the documents you want saved twice and not another
Word document someone is working on.
It then saves the file twice to the two locations and then reopens the file
that was originally open if necessary. This was you can work with either of
the 2 documents and they will both save correctly and the original file
will still be open when the code completes!
Just edit the Const statements in the above code to reflect the actual
paths you want to use. MAKE SURE that the paths terminate with a "\"
character.
HTH + Cheers - Peter
"Help with Macro" <Jerry.Lauzon@blinn.edu> wrote in news:129d501c3f62d
$f478bb20$a501280a@phx.gbl:
> Hey Gang,
> I am assisting individuals with developing their resumes
> using Word Resume Templates. There could be up to 20
> students with a wide range of computer experience. The
> students are given a disk to save & keep a copy of their
> completed resume. I also need a copy of their resume.
>
> I need a macro that will:
> 1. Use the file name already assigned to the document.
> (It will be a unique name).
> 2. Save the file to a network location: P/cisco/resume
> 3. Again save the document 'A' drive
> 4. End the macro.
>
> Your help appreciated - Thanks,
> Jerry
>
>