Open a file with notepad through VBA

前端 未结 5 626
一向
一向 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:09

    Try this approach

    Sub Test()
    Dim strCont     As String
    
    strCont = LoadFileStr$(ThisWorkbook.Path & "\Sample.txt")
    Range("A1").Value = strCont
    End Sub
    
    Function LoadFileStr$(FN$)
    With CreateObject("Scripting.FileSystemObject")
        LoadFileStr = .OpenTextFile(FN, 1).readall
    End With
    End Function
    

提交回复
热议问题