Save to Network

H

Help with Macro

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
 
P

Peter Hewett

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
 
R

richardall

I am looking for something very similar.

I need a piece of code that can be used in a form. I would like to
trigger a macro after the last field is completed. I would use the on
exit for this.

I would like a macro that would bring up the save dialog box and
automatically fill in a name based on a date. For example the file name
might be "form_yyyymmdd".

I see in this code you suggest that a path is predetermined, I could maybe
use this but would like the flexibility to use the save dialog to browse my
way to the needed location.

Any suggestions? Can you also remark the code well, I'm trying to learn
the VB and it would really help me.

Any help would be appreciated.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top