以下用了两种方法。摘自harsonliao的火宇代码库源程序中
Sub MakeFile(strFile As String) On Error GoTo err_section 'Dim fs As Object 'Dim a Dim strPath As String
strPath = CurrentProject.Path If Dir(strPath & "\Temp") = "" Then MakeSureDirectoryPathExists (strPath & "\Temp\") '文件名及路径 strPath = strPath & "\Temp\Temp.txt" '如文件已存在则删除 If Dir(strPath) <> "" Then Kill strPath
'Set fs = CreateObject("Scripting.FileSystemObject") 'Set a = fs.CreateTextFile(strPath, True) 'a.WriteLine (strFile) 'a.Close
Open strPath For Output As 1 Print #1, strFile Close #1
exit_section: Exit Sub
err_section: MsgBox "Error in cmdBuild_Click - " & Err & " - " & Err.Description Resume exit_section End Sub
|