Excel VBA Save as

Taking the easy way out and asking you smart peeps :-)

I have a variable in VBA called "filename"  
The filename value will be something like  "Bob blah blah 10.15.xlsm"... But it might be a .xls file, either way the file extension is already part of the variable.

What i want is to save as    filename (without extenstion)  &  "More Words Here" & filename (only the original extension)
LVL 11
RayData AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
You can use this to get the file name without extension which is:-

fname = Left(filename, InStrRev(filename, ".", -1) - 1)

Open in new window

Now in the fname it will store the name of the file without extension..

Also not sure what do you meant by extension which im assuming the file name extension which you can pick up by this..

xtn = Right(filename, (Len(filename) - InStrRev(filename, ".", -1)) + 1)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RayData AnalystAuthor Commented:
Sorry, was out for a long weekend :-)

Trying this today and bet it works!
RayData AnalystAuthor Commented:
Works perfect!

I converted it to one long string to use as the filename to save an updated copy of an exisiting/open file.

Left(filename, InStrRev(filename, ".", -1) - 1) & " - NEW ADDITION TO FILE NAME" & Right(filename, (Len(filename) - InStrRev(filename, ".", -1)) + 1)

Open in new window

RayData AnalystAuthor Commented:
Delivering excellent results, as usual!
Saurabh Singh TeotiaCommented:
Thanks Ray.. Always happy to help.. :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.