Calling a script from a form

  • Thread starter Thread starter Doug Sanders
  • Start date Start date
D

Doug Sanders

I have a script that works fine when called by itself. I need to execute it
from within a form or macro.

It places a short cut to a newly created folder on the users desktop.

Here it is--- Any help would be appreciated.

Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")
'link.Arguments = "1 2 3"
link.Description = "test shortcut"
link.HotKey = "CTRL+F10"
link.IconLocation = "%SystemRoot%\system32\SHELL32.dll,45" 'This points to
the desired icon
link.TargetPath = "c:\blah\Test Folder"
link.WindowStyle = 3
link.WorkingDirectory = "c:\blah"
link.Save


Thanks,
Doug Sanders
 
Doug Sanders said:
I have a script that works fine when called by itself. I need to
execute it from within a form or macro.

It places a short cut to a newly created folder on the users desktop.

Here it is--- Any help would be appreciated.

Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")
'link.Arguments = "1 2 3"
link.Description = "test shortcut"
link.HotKey = "CTRL+F10"
link.IconLocation = "%SystemRoot%\system32\SHELL32.dll,45" 'This
points to the desired icon
link.TargetPath = "c:\blah\Test Folder"
link.WindowStyle = 3
link.WorkingDirectory = "c:\blah"
link.Save

This version of the code seems to work fine as a VBA procedure, without
having to call an external script:

Dim Shell As Object
Dim link As Object
Dim DesktopPath As String

Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")
'link.Arguments = "1 2 3"
link.Description = "test shortcut"
link.HotKey = "CTRL+F10"
link.IconLocation = "%SystemRoot%\system32\SHELL32.dll,45"
link.TargetPath = "c:\blah\Test Folder"
link.WindowStyle = 3
link.WorkingDirectory = "c:\blah"
link.Save
 
Thanks,

I appreciate the quick answer.

Doug


Dirk Goldgar said:
This version of the code seems to work fine as a VBA procedure, without
having to call an external script:

Dim Shell As Object
Dim link As Object
Dim DesktopPath As String

Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")
'link.Arguments = "1 2 3"
link.Description = "test shortcut"
link.HotKey = "CTRL+F10"
link.IconLocation = "%SystemRoot%\system32\SHELL32.dll,45"
link.TargetPath = "c:\blah\Test Folder"
link.WindowStyle = 3
link.WorkingDirectory = "c:\blah"
link.Save


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
I am using this to create a shortcut to a secured access database, but
somewhere in creating the shortcut it changes my /wrkgrp to \wrkgrp.

const q = """"
strAccessPath = "C:\Program Files\Microsoft Office\Office\MSAccess.exe" & _
q & " " & q & strClientPath & q & " //WRKGRP " & _
q & "Y:\Database common\security.mdw" & q & _
" //USER " & q & strUser
objlink.TargetPath = strAccessPath
objlink.Save

The strAccessPath variable contains:
"C:\Program Files\Microsoft Office\Office\MSAccess.exe"
"C:\LocalDB\kMaint_fe.mdb" //WRKGRP "Y:\Database common\security.mdw" //USER
"kltq0377"

But the shortcut that is created contains:
"C:\Program Files\Microsoft Office\Office\MSAccess.exe"
"C:\LocalDB\kMaint_fe.mdb" \WRKGRP "Y:\Database common\security.mdw" \USER
"kltq0377"

Can someone please explain to me what is going on?
 
Sorry, found the answer.
I needed to use objlink.Arguments to set the command line options.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top