Search code examples
excelimportnotepad++notepadvba

Use VBA to open .tbl file in notepad


I'd like to use VBA to open a .tbl file in notepad (or notepad++). Basically, I have some .tbl files that I can drag and drop into notepad++ to edit, and I'd like to do that same thing through VBA. I can take care of the editing once the file is open. I just can't find anything about opening a non-txt file in notepad using VBA.

Opening in Excel destroys the formatting, so I'd like to stick with a text editor.

Thanks!


Solution

  • You can write a simple VBA module that invokes Notepad++:

    Sub Button1_Click()
        Dim res As Variant
        Dim fileToOpen As String
        Dim nppPath As String
    
        fileToOpen = "F:\test.tbl"
        nppPath = "F:\Program Files (x86)\Notepad++\notepad++.exe"
    
        res = Shell(nppPath & " " & fileToOpen, vbNormalFocus)
    End Sub