首页 > 解决方案 > 使用 VBA 删除 .txt 文件中的字符

问题描述

我正在 VBA 中创建一个程序,该程序在 Excel 中的电子表格上获取表格数据,然后将每一行作为字符串打印到 .txt 文件(将保存为 .jet 文件)。它从一个只是硬编码字符串文字的标题开始,然后打印每个 Excel 行,在该行的单元格之间交织字符串文字。在最后,它添加了一个页脚,它只是结束大括号。我坚持的部分是我无法弄清楚如何删除 .txt 文件中的最后一个逗号,因为逗号仅用于分隔数据中的条目。到目前为止,我已经准备了一个与输出文本类似的示例,其中包括我要删除的最后一个逗号: {"myid":345,"content":[ {"question": "A triangle is a shape with three straight sides?","answer": true}, {"question": "The moon is a planet","answer": false},

编辑:这是一些代码的示例。我知道其中一半不是真正的 VBA 代码或任何代码,但我试图说明我的意思:

Open Application.ActiveWorkbook.Path & "\" & filename For Edit As #1 ‘yes, I know there is no such “Edit”  
    Edit #1 SendKeys (bkspce) ‘yes, I know this is wrong.  im just saying something like sending a command to backspace, which wouldn’t work with SendKeys because it takes strings as arguments  
Close #1  
End Sub

标签: excelvbafile

解决方案


推荐阅读