rimshot609
Board Regular
- Joined
- Jun 4, 2015
- Messages
- 79
I have a macro that exports the contents from a worksheet to a text file. It works great but I need to tweak a little.
I would like to save it as a Word document with font, size, color included. I tried changing the .txt to .doc but that doesn't work. It creates a corrupt file. I would also like it to open the file to send as an Outlook message as well. I don't want it to send the message but just open in a message window with the to and subject fields already filled in as well and to have the to and from fields referenced from a worksheet. Thanks!
I would like to save it as a Word document with font, size, color included. I tried changing the .txt to .doc but that doesn't work. It creates a corrupt file. I would also like it to open the file to send as an Outlook message as well. I don't want it to send the message but just open in a message window with the to and subject fields already filled in as well and to have the to and from fields referenced from a worksheet. Thanks!
Code:
Private Sub CommandButton1_Click()
Dim myArea As Range, myAreas As Areas
With CreateObject("Scripting.FileSystemObject").CreateTextFile(ThisWorkbook.Path & "\Files\" & Sheets("Title").Range("A1") & ".txt", True)
With Sheets("Contents")
With .Range("A1", .Range("A" & Rows.Count).End(xlUp))
On Error Resume Next
Set myAreas = .SpecialCells(12).Areas
On Error GoTo 0
End With
End With
For Each myArea In myAreas
.writeline Join(Application.Transpose(myArea), vbCrLf)
Next myArea
End With
End Sub