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

问题描述 投票:1回答:1

我试图创建一个文件并将文本保存到其中。我尝试了下面的代码,但是当我使用 写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
excel vba excel-vba-mac
1个回答
1
投票

使用者 附加 添加文字到新行。

试试下面的代码

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
© www.soinside.com 2019 - 2024. All rights reserved.