我想在VBA中运行执行以下操作的代码:
我到现在所拥有的是:
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
Run Code Online (Sandbox Code Playgroud)
我得到一个运行时错误'13'不匹配,如行"a.WriteLine(rng)",该函数不接受要写入的范围.
有任何想法吗?谢谢!