Today, when writing programs, I have to repeatedly use writing text files, so I wrote a process function, hoping it will be useful to everyone.
Code:
Sub Write2File(strFile, strContent, blnAppend)
' Write to the file
' strFile file name (path), content written by strContent, whether to append blnAppend
On Error Resume Next
Set objFSO = ("")
If blnAppend Then
Set objWriteText = (strFile,8,True)
Else
Set objWriteText = (strFile,2,True)
End If
(strContent)
Set objWriteText = Nothing
Set objFSO = Nothing
'Fault-tolerant processing
Select Case Err
Case 424 "The path is not found or the directory does not have write permission."
' Case Else
Case Else Err
End Select
End Sub
Calling method:
Write2File "c:\", "dd", True
or
Call Write2File ("c:\", "dd", True)
illustrate:
1. Automatically create files;
2.Catalog cannot be created automatically