Results 1 to 2 of 2

Thread: Conditionally Run & move the .bat file shortcut(i.e .lnk file) by vba macro

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    Conditionally Run & move the .bat file shortcut(i.e .lnk file) by vba macro

    Code:
    Public Declare PtrSafe Function ShellExecute _
     Lib "shell32.dll" _
     Alias "ShellExecuteA" ( _
     ByVal hwnd As Long, _
     ByVal lpOperation As String, _
     ByVal lpFile As String, _
     ByVal lpParameters As String, _
     ByVal lpDirectory As String, _
     ByVal nShowCmd As Long) _
    As Long
    Sub FFF()
    Dim strFileName As String
    Dim strFileExists As String
     
     strFileName = "C:\Users\WolfieeeStyle\Desktop\Close Excel.lnk"
     strFileExists = Dir(strFileName)
     
     If strFileExists = "" Then
     Set FSO = CreateObject("scripting.filesystemobject")
     FSO.MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\Close Excel.lnk", Destination:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\"
     ShellExecute 0, "OPEN", "C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Close Excel.lnk", "", "", 1
     Else
     
     End If
     
    End Sub
    I am looking for a macro that will

    First Check Close Excel.lnk is located or not & if it is located then move that Close Excel.lnk to C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\ & then run that Close Excel.lnk

    & If the Close Excel.lnk file is not located then do nothing
    This macro is not working i think it has issues



    Thnx

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Conditionally Run & move the .bat file shortcut(i.e .lnk file) by vba macro

    This macro is not working i think it has issues
    which part is not working?
    is it finding the shortcut?, is it moving the shortcut if found? are there any errors?

    try changing to
    Code:
    If not strFileExists = "" Then
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width