Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel and Notepad VBA

  • 23-05-2011 9:18am
    #1
    Closed Accounts Posts: 613 ✭✭✭


    I want to allow a user to open a text file for 30 secs do some editing and then close the file controlled from Excel VBA.
    I use Shell notepad.exe path to open the file thats fine..however I cant then close it..Unload me throws up an error?
    Also I would like to only have one instance of notepad.exe so mutiple copies of the file cant be open.
    Any tips please?:confused:


Comments

  • Registered Users, Registered Users 2 Posts: 901 ✭✭✭EL_Loco


    maybe use a form that read the text file, lets the user add text and then will warn them after 30 secs, or whatever time limit you want. When they're finished write the form contents back to the text file.

    It keeps it all within excel and control under your vba code.


  • Closed Accounts Posts: 613 ✭✭✭4Sheets


    The text file is also being updated from another source.While its open(in one instance) the other source will buffer until the txt file is closed and writable again..I really think the way Im trying to do it will be easiest..why can I open with Shell but not then close the file?


  • Registered Users, Registered Users 2 Posts: 901 ✭✭✭EL_Loco


    shell just launches notepad.exe. It doesn't "track" it, or have any way of interacting with it. May something like AutoIT where you can use the window name, then issue keystrokes to the notepad file, like alt+s (to save) then Alt+F4 (to close).


  • Closed Accounts Posts: 613 ✭✭✭4Sheets


    Oh thats what I feared..I can open it easy enough but not close it too easy..
    I guess I will need to look at other methods as you say to keep all in VBA control
    Have you any suggestions re single instance of notepad.exe,is that possible?


  • Registered Users, Registered Users 2 Posts: 901 ✭✭✭EL_Loco


    you can call AutoIT functions from within vba once you have it installed. I haven't used it in ages, but essentially there's something like "window name" you can use so if the text file you're using is called "details.txt" you can see if it's open and then send key strokes.

    there's some example code in the 2nd post at this link:

    http://www.autoitscript.com/forum/topic/16956-autoitx-with-excelvba/


  • Advertisement
  • Closed Accounts Posts: 613 ✭✭✭4Sheets


    Thanks El_Loco..I will check it out!


Advertisement