0

I need to create shortcuts for selected files within selected folders. On several sites (including stackoverflow) I found the following code:

Private Sub MakeShortcut(ByVal File As String, ByVal ShortcutFolder As String, ByVal Name As String, ByVal WorkDirectory As String)
        Dim WshShell As Object = CreateObject("WScript.Shell")
        Dim NewShortcut As Object = WshShell.CreateShortcut(ShortcutFolder & "\" & Name & ".lnk")

        NewShortcut.TargetPath = File
        NewShortcut.WindowStyle = 1
        NewShortcut.IconLocation = File & ",0"
        NewShortcut.WorkingDirectory = WorkDirectory
        NewShortcut.Save()
End Function

Of course I added a reference to Interop.IWshRuntimeLibrary.dll to my Project and "Imports IWshRuntimeLibrary" within the 'general' section of the form.

Nevertheless I do get the message "Option Strict dissallows late binding" for all appearances of "whshell." and "Newshortcut."

Why am I getting this error and how can I fix it?

The Blue Dog
  • 2,475
  • 3
  • 19
  • 25
  • 5
    And you didn't think to Google for [Option Strict dissallows late binding](https://msdn.microsoft.com/en-us/library/efwbatax%28v=vs.90%29.aspx)? – The Blue Dog Feb 20 '15 at 19:02
  • turn off option strict? – Jeremy Feb 20 '15 at 19:14
  • You should explore the types located in the namespace `IWshRuntimeLibrary`. Look for types named `WshShell` and `WshShortcut`. – Bjørn-Roger Kringsjå Feb 20 '15 at 19:26
  • Possible duplicate of [Visual Basic Leave event giving errors when enabling option strict](http://stackoverflow.com/questions/35541689/visual-basic-leave-event-giving-errors-when-enabling-option-strict) – Paul Sweatte May 17 '17 at 17:10

0 Answers0