Auto save same name with different extension

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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
 
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
 
Back
Top