首页 > 解决方案 > 创建后如何写入文本文件?

问题描述

我想从 Excel 中提取单元格 A2 及其偏移量 (0,1) 并将其放入创建的文本文件中。

由于我没有为创建的文本文件声明变量,如何继续?

Sub CreateFileandWrite()
Open ThisWorkbook.Path & "\Test.txt" For Output As #1
Print #1, "Hello"
Print #1, strContent
Close #1
End Sub

标签: excelvba

解决方案


对于A2及其偏移量:

Sub FileMaker()

    Close #1
    Open "C:\TestFolder\sample1.txt" For Output As #1
        Print #1, Range("A2").Value
        Print #1, Range("B2").Value
    Close #1
End Sub

推荐阅读