Open a file with notepad through VBA

前端 未结 5 628
一向
一向 2020-12-19 23:39

I am trying to open a file with notepad.

const strfilename = \"C:\\Users\\Desktop\\abc.txt\"

set OFS = myOFSO.OpenTextFile(strfilename) 

I

5条回答
  •  醉酒成梦
    2020-12-20 00:16

    If you want to create a new text-file and want to write into it, you could use this approach:

    Sub writeToTextFile()
        Dim i As Long
        Open ThisWorkbook.Path & "\newFile.txt" For Output As #1
    
        Print #1, "This could be the first line"
        Print #1, "this the second"
    
        For i = 3 To 10
            Print #1, "this is the " & i & ". line"
        Next
    
        Close #1
    End Sub
    

提交回复
热议问题