• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to Create a Shortcut File

dparteka

Member
At the end of my macro I have the code shown below. What it does is save the file, displays a message to create a shortcut and then closes the file… it works great.

The question… is it possible to add code that would also create the shortcut (LNK) file rather than having to do it manually?

ActiveWorkbook.SaveAs Filename:=("H:\Public\PCB-QCR's\Files\") & Range("AJ2").Text & " QCR", FileFormat:=52, CreateBackup:=False

MsgBox "File saved... to complete the process a shortcut must be created in the PCB-QCR's folder"

ActiveWorkbook.Close


Thanks for the help... Dennis
 
dEEPAK... the code is much more sophisticated than what I was looking for however still very helpful, it did provide the guidance for me to figure out how to get what I needed... thanks for your help... Dennis
 
After a few days of trying to make this work I find myself back here in need of help, I just don't know enough at this point. I found this code on the internet and have been attempting to alter it. It works but not exactly the way I need it to. What it does is create a shortcut, the part I'm having problems with is where the shortcut is placed, the way it is now it goes to the Desktop. The seventh line down is a replacement for the sixth line and my attempt to show you how I want to name the shortcut and where it needs to be placed... I've attach the file that has the macro.

Code:
Sub CreatShortCut()
  Dim WSHShell
  Set WSHShell = CreateObject("WScript.Shell")
  Dim MyShortcut, DesktopPath
  DesktopPath = WSHShell.SpecialFolders("Desktop")
  Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\test.lnk")

  'Set MyShortcut = WSHShell.CreateShortcut("H:\Public\PCB-QCR's\") & Range("AJ2").Text & " QCR.lnk"

  With MyShortcut
  .TargetPath = WSHShell.ExpandEnvironmentStrings("H:\Public\PCB-QCR's\SECURITY VIOLATION - CONTACT ADMINISTRATOR IMMEDIATELY\") _
  & Range("AJ2").Text & " QCR.xlsm"
  .Save
  End With
End Sub
 

Attachments

  • Create Shortcut Macro.xlsm
    12.5 KB · Views: 1
Last edited by a moderator:
Hi,

First Always tags ur code in post.

I checked with it & found working.

Code:
Sub CreatShortCut()
 With CreateObject("WScript.Shell")
   ' With .CreateShortcut("H:\Public\PCB-QCR's\" & Range("AJ2").Text & " QCR.lnk")
   
'where shortcut to be created
   With .CreateShortcut("E:\Test\" & Range("AJ2").Text & " QCR.lnk")
       ' .TargetPath = "H:\Public\PCB-QCR's\SECURITY VIOLATION - CONTACT ADMINISTRATOR IMMEDIATELY\" _
        & Range("AJ2").Text & " QCR.xlsm")

        'File full path which shortcut is created.
        .TargetPath = "E:\ABC\XYZ\" & Range("AJ2").Text & " QCR.xlsm"
        .Save
    End With
End With
End Sub
 
dEEPAK... you make this look easy, I wish I was so smart, the code works perfectly... many thanks.

QUESTION: You suggested that I tag the code... is that done with a "
Code:
" at the beginning and a "
" at the end?
 
Back
Top