VBA question for "save as" function

T

TR Young

I am creating a Macro that will save the currently open .doc file as a .txt
file of the same name. In the following line, what do I need to change/add
to make the file save as the same name as the currently open file?

ActiveDocument.SaveAs FileName:="<current filename>.txt", FileFormat:= _

I am new to VBA, and I don't know what the code callout is for the current
filename, and I know that is what has to go in the line of code where I have
"<current filename>" typed in for this example. I also realize that I will
not need the quotation marks around the code command.
 
H

Helmut Weber

Hi,

guessing, that you want to save a copy of the doc
you are working on as txt, and maybe want to continue
working with the document.

Sub Test445()
Dim sTmp As String
With ActiveDocument
sTmp = .FullName
sTmp = Left(sTmp, Len(sTmp) - 3)
sTmp = sTmp + "txt"
.SaveAs sTmp, wdFormatText
' there are several reasons for the next 3 lines
sTmp = Left(sTmp, Len(sTmp) - 3)
sTmp = sTmp + "doc"
.SaveAs sTmp, wdFormatDocument
End With
End Sub

Note: second time you run the macro,
you overwrite the previously saved files.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

TR Young

Thank you, Helmut. Honestly, once I get to the point in my file where I save
it as a .txt file, I am finished with it and it gets kicked out to another
employee who manipulates it in Excel.
Should I replace ALL my current VBA code as follows with the code that you
supplied?

Sub Save_As_txt()
'
' Save_As_txt Macro
' Macro recorded 9/1/2006 by tyoung
'
ActiveDocument.SaveAs FileName:=".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
 
T

TR Young

Disregard the question about replacing all the code. I ended up replacing it
all, and your code did everything I needed it to do and more.
Thank you so much; I really appreciate your time!
 

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