Log in

View Full Version : Solved: Export string to text document



akn112
06-16-2009, 10:59 AM
Hi All,

it's been a while since i posted/wrote vba so i'm probably a little rusty. I need to create a .txt and export a string variable to the newly created file. how could i go about this?

ie:

dim string as strTest
strTest = "blah blah blah" & vblf & _
"blah blah blah"

'create mytest.txt
'export strTest, mytest.txt

Thanks.

akn112
06-17-2009, 06:27 AM
ended up using the long way

Dim strText As String
Dim wordapp As word.Application
Dim doc As Object
Dim intTarget As Integer
On Error GoTo err_TransferToText
Set wordapp = GetObject(, "word.application")
Set doc = wordapp.Documents.Add
Dim strFileName As String

strText = "..."

strFileName = "c:\Documents and Settings\" & Environ("username") & "\Desktop\io.txt"

If (Dir(strFileName) <> "") Then
GoTo exit_TransfertoText
End If

wordapp.selection.TypeText strText
wordapp.selection.TypeParagraph
wordapp.ActiveDocument.SaveAs strFileName, wdFormatText
wordapp.ActiveDocument.Close
wordapp.Quit
GoTo exit_TransfertoText

err_TransferToText:
Set wordapp = CreateObject("word.application")
Resume

...