Automatic Save As txt Macro?

G

Gabriele Azzaro

Hi there, hope this is not the wrong group for this q on Macros - can anyone
help me with a macro that would automatically Save As Plain Text a file -
keeping its name before the dot and just changing the extension to .txt?
What I have created naturally saves each file to the same name (NewName.txt
below):

Sub Save_As_TXT()

ActiveDocument.SaveAs FileName:="NewName.txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="",
AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False,
AllowSubstitutions:=False _
, LineEnding:=wdCRLF
End Sub

THANKS for any help!

Gabriele
 
J

Jonathan West

Hi Gabriele

Try this

Dim strName as String
strName = ActiveDocument.Name
strName = Left$(strName, InstrRev(strName, ".")) & "txt"
ActiveDocument.SaveAs FileName:="NewName.txt", _
FileFormat:= wdFormatText


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

Gabriele Azzaro

Thanks Jonathan,

unfortunately the oucome for me is always a file called Newname.txt, which
gets repeatedly overwritten by subsequent saves...
I am ignorant as to VB, but is there a way of making the line

ActiveDocument.SaveAs FileName:="NewName.txt", _

in such a way that the "Newname.txt" place is left empty and gets filled in
automatically by the macro witht the original document name + .txt?

Thanks,

Gabriele
 
C

Charles Kenyon

Dim strShortName
Dim lngNameLength As Long
strShortName = ActiveDocument.Name
lngNameLength = Len(strShortName)
strShortName = Left(strShortName, lngNameLength - 4)
ActiveDocument.SaveAs FileName:=strShortName &".txt", _

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
G

Gabriele Azzaro

Thanks, IT WORKS NOW!

Gabriele

Charles Kenyon said:
Dim strShortName
Dim lngNameLength As Long
strShortName = ActiveDocument.Name
lngNameLength = Len(strShortName)
strShortName = Left(strShortName, lngNameLength - 4)
ActiveDocument.SaveAs FileName:=strShortName &".txt", _

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

You are welcome. I've gotten a lot of help here over the years. It is good
to give some back.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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