All I am looking for is a way to launch power bi desktop
Find the application and right click to get the target address. Use that target address and query winmgmts to ensure process not already running.

Option Explicit
Public Sub test()
If GetObject("winmgmts:").ExecQuery("select * from win32_process where name='PBIDesktop.exe'").Count = 0 Then
Shell "C:\Program Files\Microsoft Power BI Desktop RS\bin\PBIDesktop.exe", vbNormalFocus
End If
End Sub
I am trying to open a Power Bi desktop ".pbix" file from VBA if the file is not opened already.
For specific PBI file:
Option Explicit
Public Sub test()
Dim fileName As String
fileName = "C:\Users\<User>\Desktop\NEL VTE Template SQL.pbix"
If Not IsFileOpen(fileName) Then
Shell "C:\Program Files\Microsoft Power BI Desktop RS\bin\PBIDesktop.exe" & " " & """" & fileName & """"
End If
End Sub
'Adapted by me from https://exceloffthegrid.com/vba-find-file-already-open/
Public Function IsFileOpen(ByVal fileName As String) As Boolean
Dim fileNum As Long
Dim errNum As Long
'Allow all errors to happen
On Error Resume Next
fileNum = FreeFile()
'Try to open and close the file for input.
'Errors mean the file is already open
Open fileName For Input Lock Read As #fileNum
Close fileNum
'Get the error number
errNum = Err
'Do not allow errors to happen
On Error GoTo 0
'Check the Error Number
Select Case errNum
'errNum = 0 means no errors, therefore file closed
Case 0
IsFileOpen = False
'errNum = 70 means the file is already open
Case 70
IsFileOpen = True
'Something else went wrong
Case Else
IsFileOpen = errNum
End Select
End Function
Ref:
- Determine if application is running with Excel
- https://stackoverflow.com/a/39903527/6241235 @Tony Emrud