How to show Windows 10 notification toast from VBA
Came across above link, with below code. However seem not able to add a $variable. Tried
# '" & sMessage & "'
strCommand = strCommand & "; $notify.showballoontip(10,'New Chat!','" & sMessage & "',[system.windows.forms.tooltipicon]::None)"
But that gave no errors but no notification either. Below the original code from above link.Which works great
Public Sub Notify_Test()
Dim WsShell As Object: Set WsShell = CreateObject("WScript.Shell")
Dim strCommand As String
strCommand = "powershell.exe -Command " & Chr(34) & "& { "
strCommand = strCommand & "[reflection.assembly]::loadwithpartialname('System.Windows.Forms')"
strCommand = strCommand & "; [reflection.assembly]::loadwithpartialname('System.Drawing')"
strCommand = strCommand & "; $notify = new-object system.windows.forms.notifyicon"
strCommand = strCommand & "; $notify.icon = [System.Drawing.SystemIcons]::Information"
strCommand = strCommand & "; $notify.visible = $true"
strCommand = strCommand & "; $notify.showballoontip(10,'New Chat!','You have received New Chat!',[system.windows.forms.tooltipicon]::None)"
strCommand = strCommand & " }" & Chr(34)
Shell strCommand, vbHide
End Sub
Edit: seems that sMessage needs to be cleaned up, an Apostrophe was the bug.