我想要:
- 复制名为“Kommentar”的工作表的使用范围
- 在与 ThisWorkbook 相同的目录中创建一个“.txt”文件(“Kommentar.txt”)
- 粘贴之前复制的使用范围
- 保存“.txt”文件
我有:
Sub CreateAfile()
Dim pth As String
pth = ThisWorkbook.path
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim a As Object
Set a = fs.CreateTextFile(pth & "\Kommentar.txt", True)
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Kommentar")
Dim rng As Range
Set rng = sh.UsedRange
a.WriteLine (rng)
a.Close
End Sub
我明白了
运行时错误“13”不匹配
该a.WriteLine (rng)
函数不接受要写入的范围。