excel - Excel VBA not writing to next text file line
问题描述
I have the following macro that is should write new data onto a new line in a text/csv file, however it overwriting the existing text in the file, I thought that write wrote to a new line as opposed to print. I am not sure what I am doing wrong
Sub picking()
Range("d14").NumberFormat = "mm/dd/yyyy"
Range("d14").Value = Now
Range("e14").NumberFormat = "hh:mm"
Range("e14").Value = Now
Range("e17").Value = "Picking"
Call outputcsv
End Sub
Sub outputcsv()
Dim Fullpath As String
Dim outputstring As String
Fullpath = Worksheets("Maintence").Range("c5")
Open Fullpath For Output As #1
outputstring = Worksheets("CSV").Range("A1")
Write #1, outputstring
Close #1
End Sub
解决方案
你只需要改变...
Open Fullpath For Output As #1
...至...
Open Fullpath For Append As #1
请注意,“输出”更改为“附加”。
另请注意,“附加”将创建文件 - 就像输出一样 - 如果它尚不存在。无需预先创建它。
推荐阅读
- laravel - Laravel 应用程序名称未按要求显示
- javascript - Visual Studio 2019 中的 Gulp 问题
- node.js - 未捕获的类型错误:fs.readFile 不是函数
- angular - 我需要在某个工作流程之前要求用户重新输入密码。如何使用 AzureB2C 实现这一目标?
- maven - Spark 应用程序构建在本地服务器中,我们如何访问位于 HDInsight 中的 Hive Warehouse
- azure - 为什么该字段不受词法分析
- gekko - 如何在 mpc 中使用矢量设置点,以便为程序提供有关未来设置点将如何变化的信息
- swift - 使用 SwiftUI 在 WatchOS 中实现从主控制器导航到基于页面的控制器的问题
- c# - C# ASP.NET API:设置 MongoDb ID
- python - 为什么我在使用 path() 而不是 url() 时得到 Page Not Found (404)?