请教VB对文本文件的操作
本人初学VB,请教VB熟手,如何编程以下操作:
用VB创建一个文件名为“***.txt”的文本文件,粘贴剪贴板里面的数据,替换字符(比如将其中的A字符全部替换为B字符),替换完成后,保存该文本文件。
请DX们不吝赐教,在此谢过!
[解决办法]
30分啊? 希望你言而有信!送你标准答案~
Private Sub Command1_Click()
Dim sStr As String
sStr = Clipboard.GetText()
sStr = Replace(sStr, "A ", "B ")
Open App.Path & "\111.txt " For Append As #1
Print #1, sStr
Close #1
End Sub
[解决办法]
引入fso:
function FSOchange(filename,Target,String)
Dim fso,f
Set fso = Server.CreateObject( "Scripting.FileSystemObject ")
Set f = fso.OpenTextFile(...TXT文件路径)
FiletempData(变量) = f.ReadAll
FiletempData(变量)=Replace(FiletempData, "A ", "B ")
f.Write FiletempData
f.Close
set f=nothing
Set fso=Nothing
End Function
[解决办法]
Public MyData As DataObject
public tStr as string
Sub myClipboard() '取得剪切板数据
'Dim tStr$
Set MyData = New DataObject
MyData.GetFromClipboard
If MyData.GetText = " " Then
Debug.Print "NO "
Else
tStr = MyData.GetText
Debug.Print tStr
End If
End Sub
Private Sub Workbook_Open() '写文件
Open ThisWorkbook.Path & "\aa.txt " For Output As #1
Write #1, tStr
Close #1
End Sub