My boyfriend coded the following for me because I wanted a simpler way of adding different internet shortcuts to his desktop (which I'm always doing when I see something online I want to share with him) rather than opening his desktop folder (over the network), right clicking, going to new, locating and clicking new shortcut in the list before finally entering the URL and naming the file.

We both searched online to find a simple solution but nothing seemed to do what we wanted (a lot of stuff to create the same shortcut over and over though!) so we gave up on it for a while and did something else. A bit later he suddenly realised there was a way to code it in VB and quickly wrote the following:

(just a blank form is needed for this code)

vb Code:
  1. Private Sub Form_Load()
  2. Dim Linky As String
  3. Dim FF As Integer
  4. Dim Addy As String
  5. Dim FileName As String
  6. Dim TextA As String
  7. Dim TextB As String
  8. Dim Exten As String
  9. Dim Randi As Double
  10.  
  11. FF = FreeFile()
  12.  
  13. Addy = "J:/Users/Username/Desktop/"
  14. Linky = InputBox("Please paste the URL!")
  15.  
  16. If Linky = "" Then
  17.     MsgBox "No File Created"
  18.     End
  19. End If
  20.  
  21. FileName = InputBox("Name to call this file")
  22. Exten = ".url"
  23.  
  24. If FileName = "" Then
  25.     Randomize
  26.     Randi = Rnd * 999999999999999#
  27.     FileName = Randi
  28. End If
  29.  
  30. TextA = "[InternetShortcut]"
  31. TextB = "URL=" & Linky
  32.  
  33. Open Addy & FileName & Exten For Output As #FF
  34. Print #FF, TextA
  35. Print #FF, TextB
  36. Close #FF
  37.  
  38. MsgBox "File Written!"
  39. End
  40. End Sub

I've linked the exe to a shortcut key combination so now when I type 'Ctrl+Alt+L' I can just paste the URL into the dialog that appears and then name the shortcut and it's done (there are quite a lot of shortcuts on his desktop now - he's going to regret making it that quick for me to do ). It even has a few fool proof features, like adding a random number for the filename if that box is left blank.

Anyway, just wanted to share as I haven't found any other VB code out there that does a similar thing.