+ Reply to Thread
Results 1 to 8 of 8

Change file name in Windows Save As Dialog

  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Change file name in Windows Save As Dialog

    Below is a an example of what I am trying to attempt, which is to pass a save as file name to the windows Save As Dialog box. This is part of my trying to understand how to manipulate windows and not specific to finding a way to write data into a text file. Through Excel (vba), the sub opens Notepad, adds text and then prompts for a save as file name. It works except the passing of the file name from the vba code to Windows Save File dialog. Any help is appreciated. This has also been cross-posted on StackOverflow.

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  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: Change file name in Windows Save As Dialog

    Hello Doc,

    It took a little time to identify the window classes to get this code to work. You can change the new file to what you want. Here is the result. Let me know if you have any questions.

    Please Login or Register  to view this content.
    EDIT: Added checking for Child Window being displayed. The DirectUIHWND interface will wait for network items to respond and be listed. This code will ensure this has happened before updating the File Name box
    Last edited by Leith Ross; 09-21-2014 at 01:02 AM.
    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 Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Change file name in Windows Save As Dialog

    Hi Leith,

    Thanks for taking a look at this. I haven't worked on windows, handles, etc. for a while and so I am a little rusty (not that I was ever any good at it to begin with). Anyways, ran the sub, but keeps going into an infinite loop looking for the "Edit" window in the Do While... Loop.

    You jogged my memory and remembered that I had a workbook by Mark Rowlinson (www.markrowlison.co.uk) that displayed all the window info in a spreadsheet. Ran it and got the following hierarchy for the 'Save As Dialog'.

    #32770
    DUIViewWndClassName
    DirectUIHWND
    FloatNotifySink
    ComboBox
    Edit

    I think your code will run through the child windows if it can get out of the loop, but not sure how to modify.

    Thanks for all your help.

    abousetta

    Edit: Just checked the text being retrieved by "Text" and in the loop it is always "MSCTFIME UI".

  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: Change file name in Windows Save As Dialog

    Hello Doc,

    If it hangs up, you can use the CTRL + Break key combination to interrupt the macro. This will work because of the DoEvents inside the loop.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Change file name in Windows Save As Dialog

    Hi Leith,

    In the Do While... Loop it seems to keep looping on only only one Retval. It doesn't want to return values for any of the other windows.

  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: Change file name in Windows Save As Dialog

    Hello Doc,

    Looks like my mistake. I didn't check that the retval was not zero.

    Replace the Child Window loop with this...
    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Change file name in Windows Save As Dialog

    Hi Leith,

    sorry man... that's wasn't it either. I did manage to find the culprit. GW_Child's value was never declared and it was giving it a 0 instead of 5.

    Please Login or Register  to view this content.
    Thanks again for looking into this for me.

    abousetta

  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: Change file name in Windows Save As Dialog

    Hello Doc,

    It was still my fault. I had those constants declared globally in another module when I tested the code. I forgot to copy them in your code when I posted. Argh!

    Great job on finding the problem. Sorry for the oversight.

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Change file name in Windows Save As Dialog

    No worries. It works now. I didn't think about that being the issue till this morning.

+ 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. windows open file dialog box
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-07-2014, 04:32 AM
  2. Replies: 4
    Last Post: 04-05-2014, 08:53 AM
  3. How to Save A File Using Dialog Box?
    By mitchivous in forum Excel General
    Replies: 0
    Last Post: 07-14-2013, 10:24 PM
  4. [SOLVED] automatic name in 'save as dialog box' ok, but does not actually save the file?!
    By Pluym in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-02-2012, 10:05 AM
  5. Windows File Dialog box problem from "Office 2000 VBA Fundamentals
    By Peter Rooney in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2006, 08:55 AM

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