vb 中textbox的内容导出为txt文件 点击Command按钮直接弹出生成的txt文件 需要手动保存txt文件

2024-12-03 14:56:20
推荐回答(3个)
回答1:

Open "f:\new.txt " For Input As #1
Dim b As String
b = StrConv(InputB(LOF(1), 1), vbUnicode)
'open 打开文件的路径 for 打开方式(这里是读取,下面的是写入和创建) as 文件号
Close #1
'以上为读取文件,以下为写入文件
Open "f:\new1.txt " For Output As #2
Print #2, b
Close #2
MsgBox "完毕 "
注释: 你把文件复制到我上面二个的地址,就可以看到效果,把你要读取的文件设置为 "f:\new.txt "或者自己改一下地址,改为你的文件地址进行读取

回答2:

那你把内容写到内存流中不就可以了 SaveFileDialog 用这个保存

回答3:

Public Function SaveFileFromTB(TxtBox As Object, _
FilePath As String, Optional Append As Boolean = False) _
As Boolean

`PURPOSE: Saves contents of text control (e.g., Text Box,
`Rich Text Box) specified by TxtBox to file specified by FilePath

`If Append = true, then TxtBox`s contents are
`appended to existing file contents
`else existing file is overwritten

`Returns: True if Successful, false otherwise

Dim iFile As Integer

iFile = FreeFile
If Append Then
Open FilePath For Append As #iFile
Else
Open FilePath For Output As #iFile
End If

Print #iFile, TxtBox.Text
SaveFileFromTB = True

ErrorHandler:

Close #iFile
End Function