View Single Post
 
Old 09-06-2010, 01:27 AM
jabberwocky12 jabberwocky12 is offline Windows 7 Office 2007
Novice
 
Join Date: Sep 2010
Posts: 2
jabberwocky12 is on a distinguished road
Default Quick Update

After hunting through various snippets of code, I have done this:

Dim sNewFileName As String

sNewFileName = ActiveDocument.FullName
sNewFileName = sNewFileName + ".txt"

Then, where the file is saved, instead of:
ActiveDocument.SaveAs FileName:="1.txt"
I have:
ActiveDocument.SaveAs FileName:=sNewFileName

These lines get the current file name and add the extension ."txt" to it.

At this stage, it looks messy, cos the file is then saved as "1.doc.txt" but I have a small freeware package that does batch file renaming, so it's easy to strip that ".doc" from it.

So, the whole macro (including convertin it to text and closing the window), now looks like this:

---
Sub SaveAsText()
'
' SaveAsText Macro
'
'

Dim sNewFileName As String

sNewFileName = ActiveDocument.FullName
sNewFileName = sNewFileName + ".txt"

Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _
True
ActiveDocument.SaveAs FileName:=sNewFileName, _
FileFormat:=wdFormatText, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, Encoding:=65001, InsertLineBreaks:= _
False, AllowSubstitutions:=False, LineEnding:=wdCRLF
ActiveWindow.Close

-----
Reply With Quote