+ Reply to Thread
Results 1 to 9 of 9

Specify size and location on screen of Notepad opened by VBA?

  1. #1
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Specify size and location on screen of Notepad opened by VBA?

    I'm using this code to open a text file. Is there a method to specify the size and location of the window that opens with the textfile?

    I'm sure there may be a better method to open the textfile, so feel free to tell me how bad this code is.

    Please Login or Register  to view this content.
    Excel 2000

    Thanks for helping me.
    Last edited by proepert; 02-17-2010 at 08:02 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello proepert,

    You can do this using the Windows API, but there are few properties or methods built-in to VBA to move and size a window or dialog. What do want to do and why is the position and size important?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello Leith,

    Thank your for your continued help, over and over again.

    I am opening a small textfile that contains user defaults. Because the file has only 20 short lines, I was hoping to reduce the size of the Notepad window to about 300x300 pixels and move it away from the center of the screen so the user can still see the Excel userform while editing the textfile.

    Thanks again for all your help.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello proepert,

    Sorry this took so long. I have been sick for a few days. A cold makes it difficult to keep all the minutia of API code straight. You will need to change the name of the UserForm in the macro to what you are using. It is in red font. The UserForm width and height (in pixels) is also marked in red . You can change these to set the size you want.

    It is important that the UserForm be activated within this event to capture the window handle. It you need to do something different, please let me know and do not try to modify this code on your own.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello Leith,

    Thanks so much for doing all this work for me. I hope you feel better soon.

    Does this code get split up, or pasted all together?

    If it will help I have attached a sample workbook and textfile for us to work with. I'm not sure where to put this code. I would also like to open the Notepad from a command button placed directly on the Excel sheet if that is possible with similar code?

    I didn't see any red in the code you posted, by the way, but I think I found the pixel values and the UserForm1 name.
    Attached Files Attached Files
    Last edited by proepert; 02-17-2010 at 11:12 AM.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello proepert,

    Thanks for attaching the files. That saved a lot of time. I revised the macro and made the changes needed to UserForm and worksheet command buttons. Everything works on my end. If you have any problems, let me know. Here is the revised macro code.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Re: Specify size and location on screen of Notepad opened by VBA?

    Leith,

    Thank you again. The form button works, but the button on the sheet is not finding the textfile. I don't understand, since the file exists and the code is identical for both buttons.

    Steve

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Specify size and location on screen of Notepad opened by VBA?

    Hello Steve,

    My fault. I thought I had saved the change. The problem is a space is missing at the end of "Notepad.exe". Here is the corrected button code.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Re: Specify size and location on screen of Notepad opened by VBA?

    Thanks so very much. Oops I clicked the wrong button for your reputation, sorry.

+ 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