VBA Create Shortcut With Dual Monitors
Posted on 2014-03-26
My version control code for Access applications sets up a shortcut on the user's desktop using the following code:
Private const mstrcModule as string = "basShortcut"
Private Sub CreateShortcut _
ByVal vstrCaption As String, _
ByVal vstrFQTargetFile As String, _
ByVal vfEachUser As Boolean _
On Error GoTo Proc_Err
Const strcProc As String = "CreateShortcut"
Dim strDeskTop As String
Dim sct As IWshShortcut_Class
'Dim sct As WshShortcut
Dim wsh As IWshShell_Class
'im wsh As WshShell
Set wsh = New IWshShell_Class
'If vfEachUser Then
strDeskTop = wsh.SpecialFolders("Desktop")
'strDeskTop = wsh.SpecialFolders("AllUsersDesktop")
Set sct = wsh.CreateShortcut(strDeskTop & "\" & vstrCaption & ".lnk")
sct.TargetPath = vstrFQTargetFile
sct.WindowStyle = 1
Set sct = Nothing
Set wsh = Nothing
VBA.Err.Raise Err.Number, , mstrcModule & "." & strcProc & vbNewLine & Err.Source
It's been working find for years, but yesterday I ran into the following problem. One of my users has dual monitors and he keeps his shortcuts on the 2nd monitor. For some reason my code always creates the shortcut on the 1st monitor. The user has been deleting the shortcut I create on the 1st monitor and continues to use the shortcut on the 2nd monitor. So obviously when the file pointed by the shortcut changed, my user had a problem.
Is there a way for my code to look for the shortcut on each of the user's monitors and replace that one with the new shortcut?