Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Desk top icon

  Asked By: Daryl    Date: Mar 18    Category: MS Office    Views: 797
  

I am using the following code 'DeskTopIcon'(Code not mine) runs
when 'Workbook_Open' runs (Shown). It sets an icon as a shortcut on
the desk top when the file is opened. The message box part of code
tells the user it is there - this is good. Unfortunately it tells
the user it is there every time it opens. I wish it to not run when
the desk top icon has been set. I have tried the 'If' code noted
in 'Private Sub Workbook_Open()'- like a lot of things I try it
doesn't work.
So thank you in advance for whatever help you may give me.

Private Sub Workbook_Open()

'If Application.names("DeskTopIcon").value = "=TRUE" Then
'Exit Sub
'End If
'Application.names("DeskTopIcon").value = "=TRUE"

Application.Run ("DeskTopIcon")
End Sub

Sub DeskTopIcon()
'This code sets a shortcut on the desktop for the active workbook.
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String

Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\" &
ActiveWorkbook.Name & ".lnk")
With MyShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set WSHShell = Nothing
MsgBox "A shortcut has been placed on your desktop for ' " &
ActiveWorkbook.Name & " '"
End Sub

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Maria Miller     Answered On: Mar 18

You could simply check for the existence of the shortcut  in
the "DeskTopIcon" subroutine just before creating the shortcut by
enclosing the shortcut creation code  inside the if...then like this:

If Not Dir(MyShortcut) <> "" Then
With MyShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set WSHShell = Nothing
MsgBox "A shortcut has been placed on your desktop  for ' " &
_
ActiveWorkbook.Name & " '"
End If

 
Answer #2    Answered By: Elias Turner     Answered On: Mar 18

Works like a dream. My VBA skills are very basic. Thanks to you I
shall hopefully get better. Again The code  is great.

 
Answer #3    Answered By: Kifah Malik     Answered On: Mar 18

I'm glad that works for you...Have no fear, the more you code  the
better you will get.

 
Didn't find what you were looking for? Find more on Desk top icon Or get search suggestion and latest updates.




Tagged: