VB cannot save as DOS-Text

K

Ken Chan

hi,

I tried using these scripts, but the file cannot be read
by Notepad, only in Wordpad. Anything wrong??

ActiveDocument.SaveAs FileName:="C:\MYOBInvoice.txt",
FileFormat:= _
wdFormatDOSText, LockComments:=False,
Password:="", AddToRecentFiles:= _
True, WritePassword:="",
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
 
H

Helmut Weber

Hi Ken,
not too clear what you are doing.
Have a look at this one:
Sub SaveAsTxt()
Dim sTxt As String ' path and filename
Dim sTmp As String ' path and filename
Set oDcm = ActiveDocument
sTxt = oDcm.FullName
' make sure that filename is *.txt
sTxt = Left(sTxt, Len(sTxt) - 4) & ".txt"
sTmp = "c:\test.doc"
oDcm.SaveAs FileName:=sTxt, FileFormat:=wdFormatDOSText
' in order to avoid an unwanted dialog
oDcm.SaveAs FileName:=sTmp, FileFormat:=wdFormatDocument
oDcm.Close
Kill sTmp
Shell "c:\windows\notepad.exe " & sTxt
End Sub
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
K

Ken Chan

hi,

I need Plain Text for my accounting software, but when I
change Word Doc into Plain Text manually, it can be read
by Notepad. When I execute the following script, only
Wordpad can read, not Notepad. Did this occur to you?

wd.ActiveDocument.SaveAs FileName:="d:\cust.txt",
FileFormat:=wdFormatText

Thanks,
 
K

Ken Chan

Tested in Word, is OK.

When I run the following script from Access, Notepad
cannot read.

I encountered problem when export direct to text, so I use
word.

Any suggestion?
Thanks.

Dim dat As Variant
Dim dat1 As Variant
Dim dat2 As Date
Dim dat3 As Variant
Dim dat4 As Variant
Dim dat5 As Variant
Dim dat6 As Variant
Dim datold As Variant

Dim RM As ADODB.Recordset

Dim wd As Object ' Declare variable to hold the
reference.
Set wd = CreateObject("Word.application")

Set RM = New ADODB.Recordset
RM.ActiveConnection = CurrentProject.Connection
RM.CursorType = adOpenKeyset
RM.LockType = adLockOptimistic

'Open Query
RM.Open "[MYOB-Invoice]", , , , adCmdTable

'Word-------------------
wd.Visible = True
wd.Documents.Add DocumentType:=wdNewBlankDocument

'create heading
wd.Selection.TypeText Text:="CoName" & vbTab & _
"Invoice#" & vbTab & "Date" & _
"CustomerPO" & vbTab
& "Item_Number" & _
"Total" & vbTab & "Inc-
Tax_Total"

datold = RM.Fields(1)

'populate data
While Not RM.EOF

dat = RM.Fields(0)
dat1 = RM.Fields(1)
dat2 = RM.Fields(2)
dat3 = RM.Fields(3)
dat4 = RM.Fields(4)
dat5 = RM.Fields(5)
dat6 = RM.Fields(6)

If dat1 = datold Then
wd.Selection.TypeParagraph
Else
wd.Selection.TypeParagraph
wd.Selection.TypeParagraph
End If
wd.Selection.TypeText Text:=Chr(34) & dat & Chr(34) &
vbTab & _
dat1 & vbTab & dat2 & vbTab & _
dat3 & vbTab & dat4 & vbTab & _
dat5 & vbTab & dat6 & vbTab

datold = RM.Fields(1)
RM.MoveNext

Wend

wd.ActiveDocument.SaveAs FileName:="d:\cust.txt",
FileFormat:=wdFormatText
 
A

Andi Mayer

Tested in Word, is OK.

When I run the following script from Access, Notepad
cannot read.

I encountered problem when export direct to text, so I use
word.

Any suggestion?
Thanks.
Check Open and Write in Access

like
Open "C/:test.txt" for Output as #1

while not rs.eof
write #1,rs!field(0) &vbtab $rs!field(1)...........
wend

close #1


If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 

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