SaveAs Modified File Name

P

Petra Liverani

Hi,

I'd like code to save a file named "XXX Source # #.#" as "XXX Section #
#.#". Someone on this list kindly gave me code to ensure that the file is
saved in the same directory but I have no idea how to change the name. I
have a feeling the InStr function could be used.

Thanks in advance.
Petra
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Petra,

Dim newname as string

newname = Left(ActiveDocument.Name, 4) & "Section" &
Mid(ActiveDocument.Name, 11)
ActiveDocument.SaveAs newname

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

Dear Doug,

Thank you so much for your reply - I tested your code and it works perfectly
for the problem I've posed. Unfortunately, the problem I posed isn't
actually my problem - I'll be more careful when I ask questions in future.

The file name I would like to change is actually not in the format "XXX
Source # #.#". It's really in the format "variable length text string +
Source + variable length text string" - the last text string will mostly be
# #.# so if it's significantly simpler to do code where the last text string
has a fixed length then that would be fine.

Thank you in advance for your patience.

Petra

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Petra,

This should do that:

Dim newname As String

newname = Left(ActiveDocument.Name, InStr(ActiveDocument.Name, "Source") -
1) & "Section" & Mid(ActiveDocument.Name, InStr(ActiveDocument.Name,
"Source") + 5)
ActiveDocument.SaveAs newname

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

Hi Doug,

That works really beautifully (just changed +5 to +6 - though I only got the
number by trial and error - I'll have to puzzle over the code to try and
figure it out). Thank you so much.

Regards,
Petra


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 

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