learnAsWeGo
learnAsWeGo

Reputation: 2282

Using TextStream Method WriteBlankLines

Sub tryMethod()

    Dim objTxt as textstream

    Dim filename as string
        fileName = "Z:\New folder\TextDoc.txt"

    Set fSo = New Scripting.FileSystemObject

    Set objTxt = fSo.OpenTextFile(fileName, ForReading)

    str = objTxt.WriteBlankLines(1)

End Sub

No matter what number I put into the brackets after calling method writeblanklines I get the following error:

expected function or variable

I have checked documentation and do not see an example for this method. First two pages of google also didn't give me an example to work off of.

Upvotes: 1

Views: 172

Answers (1)

Vityata
Vityata

Reputation: 43595

You have opened the file for reading Set objTxt = fSo.OpenTextFile(fileName, ForReading) and you are trying to write. This is how to open it for writing:

Sub TestMe()

    Dim objTxt As TextStream
    Dim fso As Object
    Dim filename As String
    filename = "C:\Users\User\Desktop\nd.txt"

    Set fso = New Scripting.FileSystemObject

    Set objTxt = fso.OpenTextFile(filename, ForWriting)
    objTxt.WriteBlankLines 23

End Sub

The MSDN documentation (from @braX comment) is not as good as one would expect - the ForWriting constant is present only in the example:

enter image description here

However, the ForWriting is present in the GitHub, maybe one day when the MSDN and the GitHub would be sync-ed it will be there as well:

enter image description here

Upvotes: 2

Related Questions