Excel VBA Save as

Ray
Ray used Ask the Experts™
on
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)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Commented:
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


Saurabh...
RayData Analyst

Author

Commented:
Sorry, was out for a long weekend :-)

Trying this today and bet it works!
RayData Analyst

Author

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 Analyst

Author

Commented:
Delivering excellent results, as usual!
Top Expert 2015

Commented:
Thanks Ray.. Always happy to help.. :-)

Saurabh...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial