如何使用 VBA for Excel for MacOS 创建文本文件

meM*_*hav 1 macos excel vba

我正在尝试创建一个文件并将文本保存到其中。我尝试了下面的代码,但是当我使用write #1时,脚本只会用新文本替换现有文本。我尝试写#0但没有成功。有什么建议。

Sub TestResultFile(output As String)
  Dim myFile As String
  myFile = Application.DefaultFilePath & "TestResults.txt"
  Debug.Print myFile
  Open myFile For Output As #1
  Write #1, output
  Close #1
End Sub
Run Code Online (Sandbox Code Playgroud)

小智 5

用户追加将文本添加到新行。

尝试下面的代码 -

Sub TestResultFile(output As String)
  Dim myFile As String
  myFile = Application.DefaultFilePath & "TestResults.txt"
  Debug.Print myFile
  Open myFile For Append As #1
  Write #1, output
  Close #1
End Sub
Run Code Online (Sandbox Code Playgroud)