Results 1 to 12 of 12

Thread: [RESOLVED] VBA Code SHELL Not Working

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Resolved [RESOLVED] VBA Code SHELL Not Working

    Hi, i am using the following code to close down an .exe program.

    Code:
    Dim sKillMagnify As String	
    sKillMagnify = "TASKKILL /F /IM Magnify.exe"	
    Shell sKillMagnify, vbHide
    I used the code in powerpoint in vista and it worked perfectly, but when i am using the code in XP i get an error on
    Code:
    Shell sKillMagnify, vbHide
    saying Run-time error '53': File not found.

    Thanks.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA Code SHELL Not Working

    Taskkill.exe and magnify.exe both are located in the system32 directory under XP. Perhaps verifying the directory path is correct that you are passing at runtime.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: VBA Code SHELL Not Working

    Hi, could you please explain further, i didnt quite understand your post.
    Thank you.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA Code SHELL Not Working

    Place a breakpoint on on "Shell sKillMagnify, vbHide" and see what the value of sKillMagnify is. It may not be the value you expect.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: VBA Code SHELL Not Working

    Hi, what do you mean by place a breakpoint.

    The exact code works perfectly on powerpoint in windows vista, but it is not working on xp so i know there is nothing wrong with the code.

    thanks

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA Code SHELL Not Working

    Well as I was saying you can not assume the code will workon different operating systems.

    In the IDE, place your cursor on the line of code to stop execution on for debugging. Then press F9. A red line will appear. Run your code and when it stops at that line. Check the value of the variable.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: VBA Code SHELL Not Working

    so i know there is nothing wrong with the code.
    as there is nothing wrong with the code it must be working fine

    you may need to provide full paths to boh the files like
    c:\windows\sysem32\taskill.exe
    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

  8. #8
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: VBA Code SHELL Not Working

    Try This Out:

    Code:
    Dim Error
    strComputer = "<Replace With Your Local Machine Name Or Remote server Name>"
    Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
    
    Error = objWMIService.Create("<Replace with Name Of Process You Want To Execute>", Null, Null, intProcessID)
    
    If Error = 0 Then
    MsgBox "Process was started with a process ID of " _
    & intProcessID & "."
    Else
    MsgBox "Process could not be executed due to error " & _
    Error & "."
    End If
    Ensure that the process which you want to trigger it's exe file must exist on System32 (c:\windows\system32) Folder

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: VBA Code SHELL Not Working

    Hi, the original code is working on another XP machine, so i know the code is working fine on both XP and Vista. I'll just use the other xp machine.
    Thanks for all the help

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA Code SHELL Not Working

    If it works on one XP and not another XP then are both accouts the same?
    If this issue is settled then please dont forget to use the thread tools and select Mark Thread as Resolved so others know its done
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: VBA Code SHELL Not Working

    It is only working on one XP, I don't understand why it dosn't work on the other XP computer, but it's not a problem.
    Thanks For All The Help.

  12. #12
    New Member
    Join Date
    May 2013
    Posts
    1

    Re: [RESOLVED] VBA Code SHELL Not Working

    The reason it didn't work on Khadafi's other XP PC is b/c that PC didn't have taskkill.exe in system32 directory.

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