Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Problem with script, please help

Hi all, i am using the script below to check for and install a desktop
shortcut. However it does not see that there is a shortcut already, but
installs it ok. I do not know if i must have a certain "referance" flagged or
not. Any help would be appreciated...


Sub testme02()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Dim testStr As String

Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")

testStr = ""
On Error Resume Next
testStr = Dir(sPathDeskTop & "\" & ActiveWorkbook.Name & ".lnk")
On Error GoTo 0

If testStr = "" Then
'not found
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.Description = "hi there"
.TargetPath = ActiveWorkbook.FullName
.IconLocation = "\\nv09002\tpdrive\TM-Recon\macro\scale.ico"
.Save
End With
Set oWSH = Nothing
Else
MsgBox "found it"
End If
end sub


--
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Problem with script, please help

The code works on my PC with Excel 2003. The 2nd time I run the program
"found it" is displayed. The workbook has to be saved in order for the code
to run properly.

I would comment out the ON Error statement and see what is really happening.
You could be getting an error and that is why you not seeing the Found It.
If an error occurs teststr will be set to "".





"Les" wrote:

Hi all, i am using the script below to check for and install a desktop
shortcut. However it does not see that there is a shortcut already, but
installs it ok. I do not know if i must have a certain "referance" flagged or
not. Any help would be appreciated...


Sub testme02()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Dim testStr As String

Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")

testStr = ""
On Error Resume Next
testStr = Dir(sPathDeskTop & "\" & ActiveWorkbook.Name & ".lnk")
On Error GoTo 0

If testStr = "" Then
'not found
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.Description = "hi there"
.TargetPath = ActiveWorkbook.FullName
.IconLocation = "\\nv09002\tpdrive\TM-Recon\macro\scale.ico"
.Save
End With
Set oWSH = Nothing
Else
MsgBox "found it"
End If
end sub


--
Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Problem with script, please help

Hi Joel, could it be because i have added the following
dim wkb as string

wkb = "Test.xls"

testStr = Dir(sPathDeskTop & "\" & wkb & ".lnk")

If i run the code, it inserts it again and then it see's it ??

--
Les


"Joel" wrote:

The code works on my PC with Excel 2003. The 2nd time I run the program
"found it" is displayed. The workbook has to be saved in order for the code
to run properly.

I would comment out the ON Error statement and see what is really happening.
You could be getting an error and that is why you not seeing the Found It.
If an error occurs teststr will be set to "".





"Les" wrote:

Hi all, i am using the script below to check for and install a desktop
shortcut. However it does not see that there is a shortcut already, but
installs it ok. I do not know if i must have a certain "referance" flagged or
not. Any help would be appreciated...


Sub testme02()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Dim testStr As String

Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")

testStr = ""
On Error Resume Next
testStr = Dir(sPathDeskTop & "\" & ActiveWorkbook.Name & ".lnk")
On Error GoTo 0

If testStr = "" Then
'not found
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.Description = "hi there"
.TargetPath = ActiveWorkbook.FullName
.IconLocation = "\\nv09002\tpdrive\TM-Recon\macro\scale.ico"
.Save
End With
Set oWSH = Nothing
Else
MsgBox "found it"
End If
end sub


--
Les

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Problem with script, please help

Is the excel workbook named Test.xls? Did you also change the line below?
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")

DIR will always return a "" if it doesn't find the shortcut.

I added a variable shortcutname to prevent problems. the file you are
testing and the file you are saving are two diffferent names

Sub testme02()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Dim testStr As String

Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")

shortcutname = sPathDeskTop & "\" & wkb & ".lnk"
On Error Resume Next
testStr = Dir(shortcutname)
On Error GoTo 0

If testStr = "" Then
'not found
Set oShortcut = oWSH.CreateShortCut(shortcutname)
With oShortcut
.Description = "hi there"
.TargetPath = ActiveWorkbook.FullName
.IconLocation = "\\nv09002\tpdrive\TM-Recon\macro\scale.ico"
.Save
End With
Set oWSH = Nothing
Else
MsgBox "found it"
End If

End Sub


"Les" wrote:

Hi Joel, could it be because i have added the following
dim wkb as string

wkb = "Test.xls"

testStr = Dir(sPathDeskTop & "\" & wkb & ".lnk")

If i run the code, it inserts it again and then it see's it ??

--
Les


"Joel" wrote:

The code works on my PC with Excel 2003. The 2nd time I run the program
"found it" is displayed. The workbook has to be saved in order for the code
to run properly.

I would comment out the ON Error statement and see what is really happening.
You could be getting an error and that is why you not seeing the Found It.
If an error occurs teststr will be set to "".





"Les" wrote:

Hi all, i am using the script below to check for and install a desktop
shortcut. However it does not see that there is a shortcut already, but
installs it ok. I do not know if i must have a certain "referance" flagged or
not. Any help would be appreciated...


Sub testme02()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Dim testStr As String

Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")

testStr = ""
On Error Resume Next
testStr = Dir(sPathDeskTop & "\" & ActiveWorkbook.Name & ".lnk")
On Error GoTo 0

If testStr = "" Then
'not found
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.Description = "hi there"
.TargetPath = ActiveWorkbook.FullName
.IconLocation = "\\nv09002\tpdrive\TM-Recon\macro\scale.ico"
.Save
End With
Set oWSH = Nothing
Else
MsgBox "found it"
End If
end sub


--
Les

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script problem - Help please Les Stout[_2_] Excel Programming 5 October 30th 05 08:56 AM
sub script out of range problem AmyTaylor[_20_] Excel Programming 5 July 27th 05 12:17 AM
Problem with printing from VB-script in Excel Jo Segers Excel Programming 2 January 28th 05 07:25 AM
Row deleting script problem jessica Excel Programming 1 October 15th 03 11:55 AM
Graph problem with VBA script Jon Peltier[_3_] Excel Programming 0 August 7th 03 02:05 AM


All times are GMT +1. The time now is 03:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"