Setting the file path

R

Roger

I'm trying to set a file path for the purpose of saving a Word Doc to the
correct folder location. The entire path, except for the specific subfolder
is constant. For example:

\\lv-abc\defaultpath\CaseDocs\variable

In the document that is being saved, "variable" is a bookmarked string of
text named CaseNumber.

So far I have:
ActiveDocument.Variables("CaseNumber").Value = CaseNumber
Options.DefaultFilePath(wdDocumentPath) =
"\\lv-abc\defaultpath\CaseDocs\"

This sets my path to the CaseDocs folder, but I can't figure out how to get
the variable "CaseNumber" into the path statement.

Word 2003: and I apologize if this isn't being sent as plain text. I set
my account options to send as plain text, but my compose window is not
showing in plain text, so I'm not sure how it's going out.

Thanks
 
J

Jay Freedman

Hi Roger,

I think there's a bit of confusion here, caused by multiple meanings for the
word "variable".

In VBA, you can have variables that are just memory locations defined within
the macro. Each one should be declared in a Dim statement and given a
specific data type, for example

Dim CaseNumber As String

The expression ActiveDocument.Variables("CaseNumber") refers to something
else, a "document variable" that is stored in the document file. I don't
think that belongs in this macro at all.

Finally, you need to fill the variable CaseNumber by retreiving the contents
of the bookmark by that name. I think this is what you want (the
space-and-underscore is a continuation marker, meaning "this line and the
next one are part of the same statement"):

Dim CaseNumber As String
CaseNumber = _
ActiveDocument.Bookmarks("CaseNumber").Range.Text
Options.DefaultFilePath(wdDocumentPath) = _
"\\lv-abc\defaultpath\CaseDocs\" & CaseNumber

An alternative to this method is shown at
http://word.mvps.org/FAQs/MacrosVBA/ChangeSaveAsPath.htm.
 

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