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:
Private Sub Form_Load()
Dim Linky As String
Dim FF As Integer
Dim Addy As String
Dim FileName As String
Dim TextA As String
Dim TextB As String
Dim Exten As String
Dim Randi As Double
FF = FreeFile()
Addy = "J:/Users/Username/Desktop/"
Linky = InputBox("Please paste the URL!")
If Linky = "" Then
MsgBox "No File Created"
End
End If
FileName = InputBox("Name to call this file")
Exten = ".url"
If FileName = "" Then
Randomize
Randi = Rnd * 999999999999999#
FileName = Randi
End If
TextA = "[InternetShortcut]"
TextB = "URL=" & Linky
Open Addy & FileName & Exten For Output As #FF
Print #FF, TextA
Print #FF, TextB
Close #FF
MsgBox "File Written!"
End
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.