繁体   English   中英

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

[英]How to create text file using VBA for Excel for MacOS

我正在尝试创建一个文件并将文本保存到其中。 我尝试了下面的代码,但是当我使用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

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

试试下面的代码-

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM