Save as in current directory

P

Petra Liverani

I would like to know the code for saving a document with a different name
and ensuring that it stays in the current directory. I've noticed there is a
CurDir function(?) but I don't know how to use it.

Thank you.

Petra
 
D

Doug Robbins - Word MVP

Hi Petra,

CurDir will return the path to the folder that appears when you use
File>Open. If you change the folder in the File>Open dialog, then CurDir
will return the path to which you changed it. If you want to save a
document into the folder from which it was open, but with a different name,
It might be better to parse the .FullName property of the document to get
the folder name.

Dim DocPath As String
DocPath = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) -
Len(ActiveDocument.Name))
'MsgBox DocPath
ActiveDocument.SaveAs DocPath & "NewFileName"

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
P

Petra Liverani

Thank you so much Doug. It works great.

Petra

Doug Robbins - Word MVP said:
Hi Petra,

CurDir will return the path to the folder that appears when you use
File>Open. If you change the folder in the File>Open dialog, then CurDir
will return the path to which you changed it. If you want to save a
document into the folder from which it was open, but with a different name,
It might be better to parse the .FullName property of the document to get
the folder name.

Dim DocPath As String
DocPath = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) -
Len(ActiveDocument.Name))
'MsgBox DocPath
ActiveDocument.SaveAs DocPath & "NewFileName"

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
is
 

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