VBA to save Word Document to .txt file

SamanthaSkilltec

New Member
Joined
Apr 11, 2019
Messages
20
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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
In that case you might use something like:
Code:
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.
 
Upvote 0
In that case you might use something like:
Code:
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.

Brilliant! Thank you!!! :)

Samantha
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top