Force to SaveAS .txt

L

LuisE

I have a button that prompts the SaveAs dialog box.
How can I get the user to be forced to save the file only as .txt
 
D

David Sisson

You can't use the built-in SaveAs dialog, read here. http://tinyurl.com/ywca5p

Something like this.

Sub Testing()
Dim MyFile$

MyFile$ = InputBox("Enter Filename without extension", "Save File")

If Len(MyFile$) > 1 Then
ActiveDocument.SaveAs MyFile$ & ".txt", wdFormatDOSText
Else
MsgBox "Save cancelled"
End If
End Sub


End Sub
 
L

LuisE

Thanks David for the prompt answer.

Just a couple of comments.
What if I need to specify a new path?

I's there any way to open the note Pad from an office application?
I'm creating a word file from the content of a textbox in Excel, any chance
of doing it Note pad?

Thanks
 
S

Steve Yandl

LuisE,

I think what I've got between the lines below might do what you want.

_____________________________________

Sub MyTextSave()
With Dialogs(wdDialogFileSaveAs)
.Format = wdFormatDOSText
.Name = ActiveDocument.Path & "\" & ActiveDocument.Name
If .Display Then
myFileName = WordBasic.FileNameInfo(.Name, 1)
End If
End With
If Len(myFileName) > 1 Then
If Not Right(myFileName, 4) = ".txt" Then
myFileName = myFileName & ".txt"
End If
ActiveDocument.SaveAs myFileName, wdFormatDOSText
ActiveDocument.Close wdSaveChanges
End If
If Application.Documents.Count < 1 Then
Application.Quit
End If
End Sub

________________________________________

You can certainly open Notepad.exe and load a specific text file from an
office application using Shell. You can also create a text file using the
Scripting.FileSystemObject object without involving Notepad. I doubt you
really want or need Notepad opened but perhaps you could explain a bit more
about what you want your users to input and what the final outcome should
be.


Steve Yandl
 

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