Macro that creates desktop shortcut

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm trying to write a macro that creates a shortcut on desktop for internet
explorer so that it opens a particular website, let's say my isp 62.30.31.74

two questions:

1st is it possible to do this?
2nd is it possible to embed it on a email so that several people have the
shortcuts created

TIA
 
I found this
Sub shortcut()

On Error Resume Next
'Dim wsShell As New WshShell
'Dim wsSCut As WshShortcut
Dim strCommandLine As String 'Command Line for shortcut to run
strCommandLine = Chr(34) & "C:\Program Files\Internet
Explorer\IEXPLORE.EXE" & "62.30.31.74" & Chr(34) '62.30.31.74
'strCommandLine = strCommandLine & " /WrkGrp " & Chr(34) &
"C:\Security.mdw" & Chr(34)
'strCommandLine = strCommandLine & " " & Chr(34) & "C:\MyDb.mdb" & Chr(34)
Set wsSCut = wsShell.CreateShortcut("D:\Documents and
Settings\jzywr0\Desktop\ShortcutTomyexplorer.lnk")
With wsSCut
.TargetPath = strCommandLine
.Save
End With

Set wsSCut = Nothing
Set wsShell = Nothing
End Sub

but does not work
if I uncomment wsshell it complains

I guess I need to add a reference though no idea which reference

any ideas?

if i uncomment
 
You can call the object without a ref:
Dim WSH As Object

Set WSH = CreateObject("WScript.Shell")

For a ref select 'Windows Script Host Object Model'. In the Object Browser
it's then called 'IWshRuntimeLibrary'.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


Am Wed, 22 Nov 2006 08:53:02 -0800 schrieb A1pro:
 
Thanks that works great

One thing i'm struggling with now is that, .targetpath seems to add quotes
(") at the beginning and end of whatever you set .targetpath to be.

Is there anyway around this. Because that way you cannot set a shortcut to a
webpage.

command needed to link to a webpage: "C:\Program Files\Internet
Explorer\IEXPLORE.EXE" 62.30.31.74

if I set .targetpath to be : "C:\Program Files\Internet
Explorer\IEXPLORE.EXE" 62.30.31.74

The result is "C:\Program Files\Internet Explorer\IEXPLORE.EXE 62.30.31.74"
which does not work.

Any ideas?

Also is there an easy way to embed this macro on an email.

So when the recipient opens the email, it will run the macro automatically

TIA
 
Ok, So I found out that if you just set targetpath to http://ipaddress it works

Now I need to create it on desktop. This has to go to several people, and I
do not know their desktop filepaths

I found this command
DesktopPath = WSHShell.SpecialFolders("Desktop"), it works fine for
scripting but I can't make it work on vba

any ideas?

TIA
 
This seems to do the programatic trick:
Sub CreateShortcut()

On Error Resume Next

Dim wsShell As Object
Dim wsSCut As Object

Set wsShell = CreateObject("WScript.Shell")

DesktopPath = wsShell.SpecialFolders("Desktop") 'Finds Desktop folder

shortcutPath = DesktopPath & "\" & "telewest.lnk" ' adds shortcut name

Set wsSCut = wsShell.CreateShortcut(shortcutPath) ' creates shortcut


With wsSCut
.TargetPath = "http://62.30.31.74" ' this selects iexplorer and sets
the ip address
.Save
End With

Set wsSCut = Nothing
Set wsShell = Nothing
End Sub

Now I'm trying to think how to distribute it.

Any way to embed this on an email?
or do security issues get on the way?

any help would be appreciated

TIA
 
Hopefully there's no way to get it executed automatically. Maybe you can
create a *.vbs file, attach that to the e-mail and ask the user to save the
attachment as a file and run it.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am Thu, 23 Nov 2006 02:57:01 -0800 schrieb A1pro:
 
Back
Top