Hi,
I'm Ajibola, an Independent Consultant here and a Microsoft user like you. I don't work for Microsoft.
The issue you are encountering could be related to the way different PCs handle line breaks and special characters in VBA code. The vbCrLf constant represents the carriage return and line feed characters (ASCII characters 13 and 10, respectively), which are used to create a new line in a text string.
Some PCs or environments might handle line breaks differently, causing issues when running the code. By replacing vbCrLf with Chr(13) (which represents only the carriage return character), you might have resolved the issue for the affected PCs, as it explicitly specifies the carriage return character without the line feed.
To further ensure cross-compatibility and consistent behaviour, you can modify the code to use only vbLf (line feed) instead of vbCrLf, as it represents the new line character without the carriage return. The modified code would look like this:
Public Function Popup(ByVal Prompt As String, Optional ByVal SecondsToWait As Integer = 0, Optional ByVal Title As String = "", Optional ByVal Buttons As VbMsgBoxStyle = vbOK) As VbMsgBoxResult
'Show a popup and wait some seconds, returns -1 if the user has not made a selection.
'Solve the problem that wss. Popup doesn't close sometimes when called directly from VBA
Dim Fso As Object 'FileSystemObject
Dim Wss As Object 'WshShell
Dim TempFile As String
Prompt = Replace$(Prompt, vbLf, """ & vbLf & """) ' Use vbLf instead of vbCrLf
On Error GoTo ExitPoint
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wss = CreateObject("WScript.Shell")
With Fso
TempFile = . BuildPath(. GetSpecialFolder(2). Path, . GetTempName & ".vbs")
With . CreateTextFile(TempFile)
. WriteLine "Set wss = CreateObject(""WScript.Shell"")" & vbLf & \_
"i = wss. Popup(""" & Prompt & """," & SecondsToWait & ",""" & Title & \_
"""," & Buttons & ")" & "" & vbLf & \_
"WScript.Quit i"
. Close
End With
End With
Popup = Wss.Run(TempFile, 1, True)
Fso.DeleteFile TempFile, True
ExitPoint:
End Function
By using vbLf, you should have a more consistent behavior across different environments, and the issue with the error message may be resolved on other PCs as well.
References
https://stackoverflow.com/questions/33813162/excel-vba-could-not-load-an-object-because-it-is-not-available-on-this-machine
https://support.microsoft.com/en-us/topic/error-message-when-using-the-excel-add-in-for-microsoft-forecaster-6-7-could-not-load-an-object-because-it-is-not-available-on-this-machine-93d2fdba-60af-2705-6ca2-c17234ffba5a
https://www.mrexcel.com/board/threads/error-could-not-load-some-object-because-they-are-not-available-in-this-machine.310385/
I hope this helps! Let me know if you have any other questions.
Kind regards Ajibola