To round off my recent set of articles about automating opening images in various applications:
I thought I’d include examples of automating Paint3D.
Launching Paint3D
You can open Paint3D by simply doing:
'---------------------------------------------------------------------------------------
' Procedure : Paint3D_Launch
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Open Paint3D (start the application)
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Usage:
' ~~~~~~
' Call Paint3D_Launch
'
' Revision History:
' Rev Date(yyyy-mm-dd) Description
' **************************************************************************************
' 1 2023-04-19 Initial Release
'---------------------------------------------------------------------------------------
Sub Paint3D_Launch()
On Error GoTo Error_Handler
'Call Shell("mspaint /ForceBootstrapPaint3D")
Call Shell("explorer.exe ms-paint:")
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: Paint3D_Launch" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub
Opening an Image in Paint3D
This turned out to be trickier than I had originally thought.
I tried all sorts of variations, but in the end I found no documentation regarding ms-paint: URI, nor any examples anywhere. Thus, the only solution I could find was to use ‘plain’ Paint with the command line switch /ForceBootstrapPaint3D which opens things in Paint3D. Thus resulting in a procedure like:
'---------------------------------------------------------------------------------------
' Procedure : Paint3D_OpenImage
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Open the specified image in Paint3D
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sImg : Fully qualified path and filename of the image to open
'
' Usage:
' ~~~~~~
' Call Paint3D_OpenImage("C:\Temp\TestImage.png")
'
' Revision History:
' Rev Date(yyyy-mm-dd) Description
' **************************************************************************************
' 1 2023-04-19 Initial Release
'---------------------------------------------------------------------------------------
Sub Paint3D_OpenImage(sImg As String)
On Error GoTo Error_Handler
'I haven't found an ms-paint: store app URI to open a file, nor
' any support documentation, so we have to use a workaround by
' using Paint and using it to lauch Paint3D
Call Shell("mspaint """ & sImg & """ /ForceBootstrapPaint3D")
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: Paint3D_OpenImage" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub