Auto save same name with different extension

G

Guest

Hello!
I am trying to figure out (if there is a way) how to automatically (using a
macro) save a .txt file to a .doc file using the same name from the .txt file.
Example without macro: Open word, open .txt file, modify the fonts and page
settings, save as, change extension to .doc. It keeps the same name, just
changes the extension.
Now, if I set up a macro to do all that, it always saves the file with the
same name like ThisFile.doc. The problem is that the filename changes all
the time (date related).

What I need the macro to do: after all the font and page changes, save the
..txt file as .doc, but use the name of the current file. So the first time I
use ThisFile.txt and it save as ThisFile.doc. Next time the file is
TheOtherFile.txt, I need it to save as TheOtherFile.doc (currently it would
save as the same from the first time - ThisFile.doc)

Thanks!
 
D

Doug Robbins

Use

Dim Fname As String
Fname = Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".") - 1)
ActiveDocument.SaveAs Filename:=Fname, FileFormat:=wdFormatDocument


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

Mark Morrell

Thank you!
Works perfect


Doug Robbins said:
Use

Dim Fname As String
Fname = Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".") - 1)
ActiveDocument.SaveAs Filename:=Fname, FileFormat:=wdFormatDocument


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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