OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
Am trying to launch Notepad++ and have it open a specific file. I see elsewhere that spaces in the path to the file to open causes grief. Yep. I can confirm it.
Tried adding double double quotes, replacing spaces with %20 but have not found the right combo. Here is version seven of the code, trying combinations of content.
Can get program to open but it keeps trying to open a file whose name is PART of a folder name in the path that has spaces. Example ...\Data Tools Dev\myfile.xml
might look like ...\Data Tools Dev\Data
Tried adding double double quotes, replacing spaces with %20 but have not found the right combo. Here is version seven of the code, trying combinations of content.
Can get program to open but it keeps trying to open a file whose name is PART of a folder name in the path that has spaces. Example ...\Data Tools Dev\myfile.xml
might look like ...\Data Tools Dev\Data
VBA Code:
Function FileExists(psFileSpec As String) As Boolean
On Error Resume Next
If Dir(psFileSpec) <> "" Then FileExists = True
End Function
'
Sub OpenFileWithNotepadPP()
Dim sPath As String
Dim sFileName As String
sPath = "C:\Users\Jim\Documents\Primary\Excel Tools and Development\Database Related\"
sFileName = "PrimaryData.XML"
If Not FileExists(sPath & sFileName) _
Then
MsgBox "That file does not exist."
Exit Sub
End If
Debug.Print sPath & sFileName
Call Shell(Chr(34) & "C:\Program Files (x86)\Notepad++\notepad++.exe " & Chr(34) & sPath & sFileName & Chr(34) & Chr(34))
End Sub