+ Reply to Thread
Results 1 to 24 of 24

using cmd by vba macro

  1. #1
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    using cmd by vba macro

    Hello Guys,

    Please Login or Register  to view this content.
    This macro has issues, It works sometimes & sometimes it didn't work
    I am unable to find the problem of this macro
    Plz Have a look Sir\Mam

    Thnx

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    Why not simple?
    Shell "cmd /c start C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Close Excel.lnk"", vbHide

  3. #3
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    I got this macro by doing google searches
    I am looking for a macro that if file exist
    Please Login or Register  to view this content.
    then first move the file to
    Please Login or Register  to view this content.
    & run the close excel.lnk nothing else I need & if the file is not located then do nothing
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    I putted this Shell "cmd /c start C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Close Excel.lnk"", vbHide
    & i run the macro but not getting any output

  5. #5
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    What output you expect? what is the Close Excel.lnk command?

  6. #6
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    output means
    I am looking for a macro that if file exist
    Please Login or Register  to view this content.
    then first move the file to
    Please Login or Register  to view this content.
    & then run the close excel.lnk & if the file is not located
    Please Login or Register  to view this content.
    then do nothing
    close excel is what (i putted this taskkill /F /IM EXCEL.EXE to notepad & save it as a .bat file & i created a shortcut link of that .bat file to desktop & named that file to close excel.lnk
    Y i created a shorcut link is whenevr i run that close excel.bat then it doesn't work if i run that close excel.bat by administrator then it works , so i created a shortcut link of closeexcel.bat which is close excel.lnk & from settings i assigned that to always run by administrator , so whenevr it will be run then it will run as admin & everything will be perfect
    Last edited by quirkybox; 08-15-2020 at 12:42 PM.

  7. #7
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    You can start taskkill directly from shell without lnk.

  8. #8
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    If u mean to say that opening task manager & kill all the excel file then yes i can do that but i am not looking for manual work bcoz i have to do this 4 times a day & 365 days of a year then this will not be a great Idea Sir
    I am looking for macro (automation. no manual work from my end )

  9. #9
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: using cmd by vba macro

    QB,

    there are a few ways to run the CMD with this coding environment. this was written long ago by me and has worked fine ever since. maybe you can get something from it:
    Please Login or Register  to view this content.
    this is the website that is most helpful for running DOS commands, IMO:

    https://www.computerhope.com/msdos.htm

  10. #10
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Bro i saw this

    Please Login or Register  to view this content.

    I dont know what to do with this & i never used such type of macros nor i have any idea of such type of macros & u know the condition also of the macro so plz help me for the same, i am not a professional vba coder sir so plz help


    & one more thing u have used xcopy & there is no copy paste in this problem Sir
    Last edited by quirkybox; 08-15-2020 at 02:05 PM.

  11. #11
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: using cmd by vba macro

    you don't know how to do what exactly? you have to be specific. that's the biggest quirk of professionals. ha ha. SPECIFICS! so....here are some questions to ask:

    => what is a public function?
    => where do I put this code in my workbook?
    => what does that code do?
    => what do the comments mean? what is "strArg"?

    see where I'm going with this? I've heard people say "I don't how to use that" for 20 years, and that doesn't help an experienced person help *you*. Can you clarify?

  12. #12
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Please Login or Register  to view this content.
    I puted this macro to macro.xlsm & I dont know anything about public function,strArg I got this macro from google search



    I know what macro should do
    The condition are below what i have to do & what macro should do

    First it should check wheather close excel.lnk is located here or not C:\Users\WolfieeeStyle\Desktop
    If not located then do nothing

    & if Close Excel.lnk is located at C:\Users\WolfieeeStyle\Desktop then first move the close excel.lnk to C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\
    & then run the close excel.lnk


    If my macro is not proper then plz change it

  13. #13
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    Please Login or Register  to view this content.

  14. #14
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: using cmd by vba macro

    some others here have tried to help, so I'm maybe I'm stepping on their toes. but maybe we're close. here's what I see. this....
    Please Login or Register  to view this content.
    ...is fine if the shortcut IS actually at that address. this....
    Please Login or Register  to view this content.
    ....should work fine. dir returns what you are checking. this....
    Please Login or Register  to view this content.
    ....should also work fine, per this: https://docs.microsoft.com/en-us/off...ovefile-method

    this....
    Please Login or Register  to view this content.
    .....is a wildcard.

    so, set some breakpoints in the code and tell us exactly which line of code is offending (not working). can you do that?

  15. #15
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Please Login or Register  to view this content.
    I used this & this is working perfect
    Awesome Bro
    What a Idea

    Awesome Solution Sir
    Have a Great Day,Awesome Day Sir
    Problem Solved
    Last edited by quirkybox; 08-15-2020 at 02:39 PM.

  16. #16
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: using cmd by vba macro

    I replicated your issue with the same directories, and this works just fine for me:
    Please Login or Register  to view this content.
    this also works just fine for me (this is MOVING the file, not COPYING it):
    Please Login or Register  to view this content.
    so obviously the FSO object works fine. I think what you were missing, is that you were running this line:
    Please Login or Register  to view this content.
    when you move a file either with the file scripting object in VBA or with the CMD shell, you HAVE to include the file name and extension too! goofy. did this solve it now?

  17. #17
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Sir i deleted that close file.lnk & close file.bat file
    bcoz the below macro close the excel, so now i dont need that .bat file & .lnk file

    Please Login or Register  to view this content.
    this macro is perfect for me
    Yes No Doubt Problem Solved Sir

  18. #18
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    @quirkybox Thanks for rep. Some times we must ask how to get aim but not how to correct wrong and difficult way :-)

    If you would like to close application without any question then you can use
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Ithink no need to use this

    Please Login or Register  to view this content.
    bcoz when we are using the below macro then In any condition excel will close itself without any question or pop up
    Please Login or Register  to view this content.
    Sub STEP2()
    shell "taskkill /F /IM EXCEL.EXE"
    End Sub
    Please Login or Register  to view this content.

  20. #20
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: using cmd by vba macro

    good! good luck to you! oh, and don't call me sir. I'm only 40 years old.

  21. #21
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Ok No Problem Bro
    Thnx

  22. #22
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: using cmd by vba macro

    @quirkybox. Think about compatibility.
    The last code will work on the MacOS also. The taskkill available only for Windows system.

  23. #23
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    No Doubt, I will go with the windows only & i am satisfied with the macro that i have recv
    Thnx for providing the Great Info To me Sir

  24. #24
    Registered User
    Join Date
    05-10-2020
    Location
    INDIA
    MS-Off Ver
    2013
    Posts
    92

    Re: using cmd by vba macro

    Please Login or Register  to view this content.
    I made this macro Sir
    Reason i made this macro is bcoz the logic which i used was not correct
    I sent u this macro only to see is this macro correct, is there any error in the macro then plz let me know
    Just see this macro has any errors or Any modifcation is needed as per u ?



    This macro does the same what i want to do
    only i have shared the macro to let u know that plz check the macro & plz let me know is it perfect or not
    Last edited by quirkybox; 08-16-2020 at 04:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Dynamic macro name / Concatenating macro name / Call a string variable as a macro name
    By vwhite in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-18-2020, 03:36 AM
  2. [SOLVED] macro showing error ( macro not found ) while trying to execute macro every 1 minute
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2018, 07:58 PM
  3. [SOLVED] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  4. [SOLVED] Macro to show Which macro didnt work in a nested macro
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-10-2013, 03:21 AM
  5. Perform macro "on open" specific file- store macro in Personal Macro Workbook?
    By thompssc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2012, 12:38 PM
  6. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM
  7. Cannot find macro error when running a macro from a macro in a diffrent workbook.
    By Acrobatic82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2010, 09:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1