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.

--
I'm just a simple man, trying to make my way in the universe...

Re: VBA question for "save as" function by Helmut

Helmut
Fri Sep 01 14:26:57 CDT 2006

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"



Re: VBA question for "save as" function by TRYoung

TRYoung
Fri Sep 01 14:38:01 CDT 2006

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

--
I''m just a simple man, trying to make my way in the universe...


"Helmut Weber" wrote:

> 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"
>
>
>

Re: VBA question for "save as" function by TRYoung

TRYoung
Fri Sep 01 14:47:01 CDT 2006

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!
--
I''m just a simple man, trying to make my way in the universe...


"TR Young" wrote:

> 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
>
> --
> I''m just a simple man, trying to make my way in the universe...
>
>
> "Helmut Weber" wrote:
>
> > 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"
> >
> >
> >