# VBA to save Word Document to .txt file



## SamanthaSkilltec (Apr 24, 2019)

Hi guys

Not strictly an Excel Q and I'm sure this is really simple but I am seriously losing the will to live right now!!

I need a macro that will:

1. Save the already open word document to a text file with the same name but me the option to choose the file path
2. Re-save the Word document as a Word Macro-Enabled file, in the folder it was already in (or close the document without saving it?)
3. Close the document (bonus - I can probably manage this bit myself)

I've managed to get bits of it working here and there but have spent all day trying without success to add bits from other VBA code I've found and all I've done is managed to mess it up so bad that nothing works and I threw a hissy fit and deleted the lot.  But I really do need this code!!

Any advice will be HUGELY appreciated!!

Thank you!

Samantha


----------



## Macropod (Apr 24, 2019)

Why do you want to save the document as a Word Macro-Enabled file? Does it (not just the template it's attached to) contain macros? Has the document been saved before? If it has and it was previously saved as a normal Word document, have you added macros to it since then?


----------



## SamanthaSkilltec (Apr 25, 2019)

Macropod said:


> Why do you want to save the document as a Word Macro-Enabled file? Does it (not just the template it's attached to) contain macros? Has the document been saved before? If it has and it was previously saved as a normal Word document, have you added macros to it since then?



Hi!  Thanks for coming back to me 

I assume it needs to be macro-enabled as I will need to run the macro on that document from within Word?  If it's saved as a normal Word document then I can't see the macros and the ones on my quick access toolbar won't run either.

Samantha


----------



## SamanthaSkilltec (Apr 25, 2019)

Sorry, I just re-read your reply and I think I understand what/why you're asking.

So the file is macro-enabled to start with... it's a feedback form that we get our clients to complete.  The client does File > Save As and saves with their own name then the completed form is sent to me by email.  I then want to open it, run this macro to save as a text file then close the document.  

Perhaps it doesn't need to be re-saved as a word document at all?  It can be closed without saving changes?

Samantha


----------



## Macropod (Apr 25, 2019)

In that case you might use something like:

```
Sub Demo()
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = Split(ActiveDocument.FullName, ".doc")(0) & ".txt"
  .Format = wdFormatTextLineBreaks
  .AddToMru = False
  .Show
End With
ActiveDocument.Close False
End Sub
```
The above codes displays the SaveAs dialog with the same path & name as the original document pre-filled, except for the file type being changed. After saving, the document is closed without saving changes. Rather than adding the code to the document, you'd add it to the template it's attached to.


----------



## SamanthaSkilltec (Apr 25, 2019)

Macropod said:


> In that case you might use something like:
> 
> ```
> Sub Demo()
> ...



Brilliant! Thank you!!! 

Samantha


----------

