首先引用 項目 microsoft scripting runtime
添加如下代碼
Dim FILEPATH As FileSystemObject, PATHSTR As TextStream
dim xxxx as string,dddd as string
xxxx="c:\temp\sss.txt" '文件路徑
dddd="寫入文檔內的字符"
Set FILEPATH = CreateObject("Scripting.FileSystemObject")
if FILEPATH.FileExists (xxxx) then
'文件已存在
else
'文件不存在
Set PATHSTR = FILEPATH.CreateTextFile(xxxx, True)
PATHSTR.WriteLine dddd
Endif