+ Reply to Thread
Results 1 to 9 of 9

How would I save a text file to a folder on the users desktop without knowing the path?

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    How would I save a text file to a folder on the users desktop without knowing the path?

    Currently I am copying ranges to notepad and letting the user choose the path to save to. However, this gets pretty annoying after 10 or 20 times of doing it. Is there a way to save the text file automatically?

    Please Login or Register  to view this content.
    Preferably creating a folder on the users desktop and saving the file in there with a variable name. As this is new territory to me I appreciate any help.
    Last edited by 111StepsAhead; 05-21-2012 at 01:19 PM.

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    StevenM,

    Thank you for that line. I've managed to create a folder on my desktop.

    Please Login or Register  to view this content.
    My other question is how do I saveas the notepad file that is "in focus"?

  4. #4
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    Don't run from the VBE (because of SendKeys).

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    Weird. I kept updating this thread all day and never saw your last post StevenM. I appreciate you putting in the time to make that but I am unable to save the file in the new directory I created with the above code. (ie I can't change the directory correctly.)

    Please Login or Register  to view this content.
    I guess sendkeys is as unstable as they say. Guess I'll have to find a better way to export the information but if you know what the issue is let me know. Thanks!

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    Personally, although I was able to get it to work, I wouldn't use SendKeys. I don't know why you would want to use NotePad when you can use Excel VBA to open, read, & write text files without NotePad.

  7. #7
    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: How would I save a text file to a folder on the users desktop without knowing the path

    Hello 111StepsAhead,

    Here is a macro to copy a Range into a newly opened instance of Notepad. Copy and paste this code into a new standard module.
    Please Login or Register  to view this content.

    Here is an example of using the macro.
    Please Login or Register  to view this content.
    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!)

  8. #8
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How would I save a text file to a folder on the users desktop without knowing the path

    Leith and Steven,

    Thank you for your help. I had been using notepad because I originally needed the user to be able to copy the data to another application that can't be easily interfaced with or have the option to save the text file. My plan in this thread was to automatically save the text file in a location and let the user go back and get what they need. My solution came from http://www.cpearson.com/excel/ImpText.aspx. Basically it cuts out notepad, like Steven suggested, and appears to work much quicker than sendkeys.

  9. #9
    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: How would I save a text file to a folder on the users desktop without knowing the path

    Hello 111StepsAhead,

    Copying data to another application using SendKeys is not ideal and complex. Now you know both ways to do it. Thanks for the feedback.

+ 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