+ Reply to Thread
Results 1 to 12 of 12

Closing Notepad from Excel

  1. #1
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Closing Notepad from Excel

    In my spreadsheet, a series of macros calls an external program/application three times. Each time the program finishes, it (and not Excel, as I formerly thought) opens a resource (*.res) file in Notepad, which of course goes into the taskbar. Since I need to run the spreadsheet seven or eight times in a row, the taskbar can get cluttered quickly.

    The program opens three different instances of the same filename: iroutine.res.

    Is there a way to get Excel to close these Notepad files (if it's simpler to do, it can kill all instances of Notepad) when it finishes running its routines? Thanks.
    Last edited by logicada; 09-04-2009 at 02:22 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Closing Notepad from Excel

    You'll have to experiment with using the SendKeys call inside your macro. It's tricky to use, basically sending "ketystrokes" into the windows environment. But that's the only method I can think of.

    I have used SENDKEYS to open notepad, paste in the contents in memory and save/close notepad.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Closing Notepad from Excel

    Try this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Re: Closing Notepad from Excel

    I'm not a programmer. I have only a very basic understanding of VBA.

    Do I put all of that code into a new module? How do I call it from the module that calls the various other modules? Thanks.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Closing Notepad from Excel

    This runs the close
    Please Login or Register  to view this content.
    If you want to call it as part of another Procedure use
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Re: Closing Notepad from Excel

    I put the whole thing into a module (since I don't know what else to do with it). I then put CloseNotepad into the main routine module (which calls all the other sub functions. When I try running the spreadsheet, I get an "Ambiguous name detected" error message, and the debugger opens to CloseNotepad or Call CloseNotepad, which I also tried.

    Am I supposed to put all of the code into a module or somewhere else?

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Closing Notepad from Excel

    Have you put the whole of the CloseNotePad Procedure in both Modules?

  8. #8
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Re: Closing Notepad from Excel

    You're referring to putting the entire several lines of what you posted into both modules? No, only a new module.

    I first tried to paste the entire code into the module that called the various other modules/subroutines. I got a message saying that only comments could appear after End Sub.

    Then I tried putting the whole thing into one module and tried calling it from the main module with fCloseApp and CloseNotepad (and with each prefaced by Call). All gave me an ambiguous name error.

    What I need to find out is where to put everything. I didn't (and wouldn't know how to) program this spreadsheet; it was done by somebody else many years ago, and I don't know where to find him anymore. It has several modules, all with subroutines. One module calls all of the others.
    Last edited by logicada; 09-04-2009 at 01:43 PM.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Closing Notepad from Excel

    Can you attach the workbook?

  10. #10
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Re: Closing Notepad from Excel

    After much trial and error, I managed to solve where to put the code and how to make it work.

    I put the entire code into the main module (and not into its own module). That ran the spreadsheet, but an alert sound occurred, and the routine finished itself normally. No Notepad windows closed.

    The alert I'd received was Notepad asking me if I wanted to save the changes to an open Notepad file (not one opened by the routine) that hadn't been saved yet.

    After saving all text files, I ran the routine again. It closed one instance of Notepad, but not the others.

    I then tried adding three consecutive instances of CloseNotepad near the end of the main module (after the three Notepad files had opened to the taskbar). That also only closed one instance of Notepad.

    I then tried adding CloseNotepad directly after each subroutine that opened the instance of Notepad. This worked.

    The only proviso is that I need to not have any Notepad files open when I run the program, as the routine will only close the first instance it finds. but that's fine with me.

    Thanks for the code/routine. It will save me a lot of hassle in the future.
    Last edited by logicada; 09-04-2009 at 02:43 PM.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Closing Notepad from Excel

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  12. #12
    Registered User
    Join Date
    11-07-2005
    Posts
    10

    Re: Closing Notepad from Excel

    I finally figured out how to put the Solved tag on.

    Now I'm trying to figure out how to rate the answers, other than clicking the scale thing or saying so in the forum.
    Last edited by logicada; 09-04-2009 at 02:44 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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