Word VBA >> VB cannot save as DOS-Text

by Ken Chan » Thu, 05 Aug 2004 14:29:41 GMT

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


Word VBA >> VB cannot save as DOS-Text

by Helmut Weber » Thu, 05 Aug 2004 19:00:35 GMT


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



Word VBA >> VB cannot save as DOS-Text

by Ken Chan » Thu, 05 Aug 2004 23:27:20 GMT

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,


VB cannot save as DOS-Text

by Ken Chan » Thu, 05 Aug 2004 23:33:05 GMT

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



VB cannot save as DOS-Text

by Andi Mayer » Fri, 06 Aug 2004 06:43:56 GMT

On Thu, 5 Aug 2004 08:33:05 -0700, "Ken Chan" < XXXX@XXXXX.COM >


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


VB cannot save as DOS-Text

by Ken Chan » Fri, 06 Aug 2004 13:40:03 GMT

Open & Write in Access is working.

Thanks!

: )


Similar Threads

1. Text file printout in dos mode through VB.Net or DOS command from VB.Net

Hi,

I am generating a text file through vb.net and I want to give facility to my
user to take DOS base (fast) printiout of it ,

or in other words,

I want to run DOS command from my application. i.e. TYPE C:\TEST.TXT >PRN ,
How can I ?

Regards,


Hardik Shah


2. Save As' option of 'MS-DOS Text with Layout' - Microsoft Office

3. Save as MS Dos text with layout

Word 2003 - is there a way to add this feature to the word 
program. it seems that this conversion was omitted in the 
new version; yet, was supported in Word 2002.

4. saving as a MS-DOS with text layout or asc file

5. Calling VB pgm from DOS, thence exiting to DOS after a CHDIR

I tend to do just about everything from a DOS window.

I call my VB (5.0) application from DOS.  Under certain circumstances,
I wish to exit the VB application in a different directory.  My VB
program issues the ChDir statement, but when I end the program and go
back to DOS, the DOS directory has not changed.  Is there a way to do
this?

6. copy text string from a 3rd party DOS application using VB - Visual Basic/VB

7. cannot save References list in VB

The subject line on this message makes it seem as if I 
know what I'm doing in Access, but I only knew to check 
for a References problem because of previous help from 
this newsgroup.  I think that if I could save an updated 
list of references, I could fix my current problem, but I 
always get a "Save action failed" message.  I am trying to 
remove a "MISSING" reference to the "Microsoft ActiveX 
Data Objects Recordset 2.7 Library."  I tried deleting and 
re-linking, but I suspect the dll doesn't even exist on 
that computer.  I apparently "caused" the original problem 
by exporting some queries, forms, and macros from an XP 
machine to to an Access file on this computer, which I 
think runs Win2000.  I think both machines have the 
updated Jet engines.

The symptom is that the database with the imported objects 
doesn't recognize certain functions like Date().  Going 
into the VB application and choosing Tools/References 
reveals the missing 2.7 library.  I can delete the file 
from the list, and Access runs fine -- I just can't *save* 
the references list with the deletion.  So each time one 
opens Access, one has to go through the deletion procedure 
to get the database to run right.  This is not considered 
much of a solution by my associates.

Why can't I save the References list?  Have I corrupted 
the database by moving objects into it from another 
machine (both of them running Access 2000)?  How would I 
check this?  Oh, I did run a Compact and Repair Database 
remotely on that machine, and it took forever.  I guess 
that could have caused the problem too.  Any insight would 
be much appreciated.

8. Personal digital signature cannot be saved in VB