Re: Programming Macro for Save As in Word 2003




Hi Graham,

There would not be anything in the Document that identifies the drill down
info for the Policy.

I'm currently trying to build a Template for the Policies so all of the
Documents had better be laid out the same!! I haven't rolled out the Template
yet so what I am trying to do is set it up so that when they tab out of the
bookmarked title field it comes up somehow that it get's saved as the title
marked as a draft in the R:\Governance\Policy\(whichever it happens to
be)\Draft folder.

I will email you a copy of the Template I have so far, with a cover note
stating what I want it to do hopefully you can help me..I think I bit off a
bit more than I can chew but at least I'm learning!!

"Graham Mayor" wrote:

If the Policy information is contained in the document, then it would be
possible to extract it from there, save the document in the correct
location, and thus avoid the user having to screw up anything.
How many policies are there?
Are all the documents laid out the same?
Is there anything in the documents that identifies the Policy type?
Is it in the same place in each document?

If the documents are similar, perhaps you could send me one (with dummy
information) to the link on my web site, with a covering note explaining how
it works?

Otherwise adding a box for the user to select the document type - and thus
the save location would not be too difficult to arrange e.g.

Sub SaveAs()
Dim iPolicy As String
Dim PolPath As String
Dim pStr As String
Start:
pStr = "R:\Governance\Policy\"

iPolicy = InputBox("Enter the number of the document type:" & vbCr & _
vbCr & "1. Corporate Services" & vbCr & _
"2. Financial Management" & vbCr & _
"3. Relationship Management", "Policy Type", 1)
Select Case iPolicy
Case Is = 1
PolPath = "Corporate Services\"
Case Is = 2
PolPath = "Financial Management\"
Case Is = 3
PolPath = "Relationship Management\"
Case Else
MsgBox "The number entered is not valid!", vbCritical, "Error!"
GoTo Start
End Select
pStr = pStr & PolPath & _
ActiveDocument.Bookmarks("bktitle").Range.Text _
& " Draft.doc"
ActiveDocument.SaveAs FileName:=pStr
End Sub

You could create a userform insteadof the InputBox with radio buttons which
would be neater, but more difficult to convey in a forum like this.

For the basics, see Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm

for a more in depth explanation, see
http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Nadihaha wrote:
Ok I will attempt to explain

The R:\Governance\Policy folder doesn't allow people to save in it (I
now realise that's where my problem was with the Macro)

Depending on what the Policy is for will depend on where you go from
here - Corporate Services, Financial Management, Relationship
Management etc.

In each of these there should then be a draft folder (there will be
once I get that fixed) this is where the template should go.

I read about a message box that allows you to click on a button and
store the value, and I was thinking would it be possible to have the
buttons relate to each of the subfolders and when the user selects
the appropriate button it stores this value somewhere so that the
macro can appropriately drill down? or is this way to ambitious? I'm
trying to avoid having to open the dialog box as our staff tend to
misplace things when saving but if that's what I have to do that will
be what I have to do.

Thanks for your help so far

"Graham Mayor" wrote:

They may have existed but they were no addressed in your version of
the macro. They should have been in mine.
The macro I reproduced will *only* save the documents in the folder
R:\Governance\Policy
If you want it to save elsewhere, then the macro needs to be able to
identify where to save it, from repeatable information that the
macro can access, or you will have to tell it where to save the
documents by changing the path above or by opening a dialog box to
select the save location.
If you can tell us more about the filing policy and/or how you wish
the macro to identify where to save the document, we can advise
further.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Nadihaha wrote:
Ok but they both do already exist.

Bookmark bktitle is in the Active Document and the Path
R:\Governance\Policy is the location on our Directory I want the
files to be saved.....Oh I get it this is the top of the network
structure where it needs to go.

We don't get access to save the documents until further down the
tree. I want everyone to be able to use the template but it
obviously needs to go into different branches, is there an easy way
of getting it to do this, or should I just give up and hope people
know where to save them?

Thanks

"Graham Mayor" wrote:

You have a couple of obvious errors where you have misunderstood
Greg's help text

Sub SaveAs()
Dim pStr As String
pStr = "R:\Governance\Policy\"
pStr = pStr + ActiveDocument.Bookmarks("bktitle").Range.Text
pStr = pStr + " Draft"
ActiveDocument.SaveAs FileName:=pStr
End Sub

The bookmark bktitle and the path "R:\Governance\Policy\" must
exist and be available to the macro for it to work.

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Nadihaha wrote:
Ok I tried the above suggestion. If I put it all in the section of
text from or do it all together goes red, and it doesn't work.
So I tried removing it and when I try to test the Macro I get the
error "Compile Error: Invalid Outside Procedure"

This is what I put in

Sub SaveAs()
Dim pStr As String
pStr = "R:\" 'Governance\Policy
pStr = pStr + ActiveDocument.Bookmarks("FileName").Range.Text
'bktitle pStr = pStr + " Draft"
ActiveDocument.SaveAs FileName:=pStr
End Sub

Also just entering the Or do it all together section doesn't work
either!

what am I doing wrong :(

"Nadihaha" wrote:

Many Thanks I'll give that a go

"Greg Maxey" wrote:

Something like this:

Sub ScratchMacro()
Dim pStr As String
pStr = "C:\" 'Your directory
pStr = pStr + ActiveDocument.Bookmarks("FileName").Range.Text
'Your bookmark name
pStr = pStr + " Draft"
ActiveDocument.SaveAs FileName:=pStr
'Or do it all together
ActiveDocument.SaveAs FileName:="C:\" &
ActiveDocument.Bookmarks("FileName").Range.Text & " Draft"
End Sub



Nadihaha wrote:
Ok I have created a template and am slowly getting the
functionality I require. I think I can get it to save as once
the title is entered in one of my fields (which I have
bookmarked) how to I program it to save in specific location,
named as per the bookmarked Title and add "draft" on the end?

Is this asking to much of what can be done?

Any help greatly appreciated

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org



.


Loading