假如有3个textbox,可以这样:Open "d:\mc\mytemp2.txt" For Binary As #1 Put #1, , Text1.Text Put #1, , Text2.Text Put #1, , Text3.Text Close #1也可以这样:Dim s As String s = Text1.Text & Text2.Text & Text3.Text Open "d:\mc\mytemp.txt" For Binary As #1 Put #1, , s Close #1
open "d:\temp.txt" for output as #1 print #1,text1.text print #1,text2.text print #1,text3.text '依次类推......... close #1
Dim OFSO As New Scripting.FileSystemObject Dim Txt As TextStream Set Txt = OFSO.OpenTextFile("c:\txt.txt", ForWriting) Txt.Write text1.Text Txt.Close如果要倒入到WORD里面有一点麻烦
Private Sub Command1_Click() Dim TempFile As Long Dim SaveBytes() As ByteSaveBytes = StrConv(Text1.Text & Text2.Text & Text3.Text, vbFromUnicode)TempFile = FreeFile Open "f:\new.txt" For Binary As #TempFile Put #TempFile, , SaveBytes Close TempFileEnd Sub
贴点代码作参考: Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fs, f Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile("c:\a.txt", ForAppending, True) f.writeline "嗨,你好!" 'or f.write "嗨,你好!" f.CloseDim MyChar Open App.Path & "\a.txt" For Input As #1 ' 打开文件。 Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入一个字符。 Debug.Print MyChar ' 显示到立即窗口。 Loop Close #1 ' 关闭文件。Dim TextLine Open App.Path & "\a.txt" For Input As #1 ' 打开文件。 Do While Not EOF(1) ' 循环至文件尾。 Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。 Debug.Print TextLine ' 在立即窗口中显示数据。 Loop Close #1 ' 关闭文件。
1. Dim ss As Stringss = Text1.Text & Text2.Text & Text3.TextOpen "C:\a.txt" For Output As #1 Print #1, ss Close #12. 点击菜单 "工程/引用/Microsoft Word 9.0 Object Library"Dim wd As New Word.Applicationwd.Documents.Add wd.Selection.TypeText Text:=ss '文件内容 wd.ActiveDocument.SaveAs FileName:="c:\dd.doc", FileFormat:= _ wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _ True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False
const intLen as integer=10 '假设你要写入的固定长度 str1 as string *intlen str2 as string *intlen str3 as string *intlenopen "d:\temp.txt" for output as #1 str1=text1.text str2=text2.text str3=text3.textprint #1,str1 '这里可以用Format函数设置你需要的格式 print #1,str2 print #1,str3 ...... close #1
Put #1, , Text1.Text
Put #1, , Text2.Text
Put #1, , Text3.Text
Close #1也可以这样:Dim s As String
s = Text1.Text & Text2.Text & Text3.Text
Open "d:\mc\mytemp.txt" For Binary As #1
Put #1, , s
Close #1
print #1,text1.text
print #1,text2.text
print #1,text3.text
'依次类推.........
close #1
Dim Txt As TextStream
Set Txt = OFSO.OpenTextFile("c:\txt.txt", ForWriting)
Txt.Write text1.Text
Txt.Close如果要倒入到WORD里面有一点麻烦
Dim TempFile As Long
Dim SaveBytes() As ByteSaveBytes = StrConv(Text1.Text & Text2.Text & Text3.Text, vbFromUnicode)TempFile = FreeFile
Open "f:\new.txt" For Binary As #TempFile
Put #TempFile, , SaveBytes
Close TempFileEnd Sub
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\a.txt", ForAppending, True)
f.writeline "嗨,你好!"
'or f.write "嗨,你好!"
f.CloseDim MyChar
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
MyChar = Input(1, #1) ' 读入一个字符。
Debug.Print MyChar ' 显示到立即窗口。
Loop
Close #1 ' 关闭文件。Dim TextLine
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Debug.Print TextLine ' 在立即窗口中显示数据。
Loop
Close #1 ' 关闭文件。
Dim ss As Stringss = Text1.Text & Text2.Text & Text3.TextOpen "C:\a.txt" For Output As #1
Print #1, ss
Close #12.
点击菜单 "工程/引用/Microsoft Word 9.0 Object Library"Dim wd As New Word.Applicationwd.Documents.Add
wd.Selection.TypeText Text:=ss '文件内容
wd.ActiveDocument.SaveAs FileName:="c:\dd.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
str1 as string *intlen
str2 as string *intlen
str3 as string *intlenopen "d:\temp.txt" for output as #1
str1=text1.text
str2=text2.text
str3=text3.textprint #1,str1 '这里可以用Format函数设置你需要的格式
print #1,str2
print #1,str3
......
close #1