Results 1 to 10 of 27

Thread: VBA Dir File Copy and Paste: Check if file exists then copy file from one directory to another. Bat File

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

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

    Hi Experts,

    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

    https://www.vbforums.com/showthread....)-by-vba-macro
    https://chandoo.org/forum/threads/co...a-macro.44815/
    https://www.excelforum.com/excel-pro...ml#post5378034
    https://www.ozgrid.com/forum/index.p...-by-vba-macro/
    Last edited by fixer; 08-12-2020 at 11:29 AM.

  2. #2
    Junior Member
    Join Date
    Jul 2020
    Posts
    3
    Rep Power
    0
    Problem Solved

  3. #3
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    This Problem is not Solved, I have this macro & it works sometimes & sometimes it doesnt works
    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 STEP2()
    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

  4. #4
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Problem Solved
    Another macro has made a mistake & it is working perfect
    Thnx Alot Sir

Similar Threads

  1. Replies: 85
    Last Post: 06-09-2020, 05:58 PM
  2. Replies: 4
    Last Post: 05-08-2014, 10:12 PM
  3. Replies: 7
    Last Post: 08-28-2013, 12:57 AM

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
  •