+ Reply to Thread
Results 1 to 8 of 8

Pasting Excel data to Notepad

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    7

    Pasting Excel data to Notepad

    Hi,
    I need help completing a macro.

    I need to copy data from an excel worksheet into a notepad file on a daily basis.
    The data from excel changes modestly from day to day and I need to completely update (replace) the contents of the notepad file everytime I run the macro.

    So far I have:
    Please Login or Register  to view this content.
    This does a great job of copying the correct data from excel, opening notepad, and pasting the data into notepad.
    But...What I need is it to replace everything that is already in the data100.txt document.

    I thought that if I could force notepad to "select all" by inserting SendKeys "^A" like this:

    Please Login or Register  to view this content.
    that the paste would replace the existing data. But it isn't. It only pastes the new data after the existing data.
    After the paste I also need to save & close the notepad file.

    Any help would be much appreciated as I am very new to VBA and have struggeled with this for most of the day.
    Thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Pasting Excel data to Notepad

    Why not just kill the notepad file first and start a new one?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Pasting Excel data to Notepad

    Hmm? I didn't think if that.
    The thing is I need to repeat this process 10-15 times, then the notepad files are loaded into another program. I suppose if I just erased the original .txt file and created a new one with the same name this would work.

    Do you mind showing me how to do that?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Pasting Excel data to Notepad

    One option:

    Please Login or Register  to view this content.

    courtesy of: http://stackoverflow.com/questions/6...-a-file-in-vba


    Regards, TMS

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Pasting Excel data to Notepad

    Thank you.
    That code works for deleting the existing .txt file.
    But now my problem is Saving the new .txt file as the same name.
    Also, the paste code stopped working.

    Any idea where this is falling apart? Thanks

    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Pasting Excel data to Notepad

    I suggest you record a macro while you save the file with your particular flavour of Text file.

    This is what I got, after editing a little:

    Please Login or Register  to view this content.

    Regards, TMS
    Last edited by TMS; 05-09-2013 at 09:19 AM.

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Pasting Excel data to Notepad

    Thank you. This has been very helpful.

    I'm new to VBA and close to getting this to work, but I'm still a step or two away from completion.

    Let me back up and explain what I need to do from a broader level.

    There is a sheet in Excel named 100, that pulls in data. That data is manipulated by simple excel functions. I need to then paste the manipulated data only, into a .txt document named 100.txt. This process must be repeated for 10 differernt sheets (101.txt, 102.txt etc...).

    I suppose that I could have another sheet in excel named 100x that references only the needed cells from 100.
    Then save the data from 100x into 100x.txt.

    Keep in mind that I'd like to be able to repeat this process for 101x.txt, 102x.txt ...etc...

    This is what I have so far:

    Please Login or Register  to view this content.
    This code works for:
    deleting the previous 100x.txt document
    saving the new 100x.txt document properly

    But I can't figure out how to close 100x.txt and then repeat the process for 101x.txt

    Does that make sense?
    Thanks again, I appreciate your patience with me.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Pasting Excel data to Notepad

    I suggest that you post a sample workbook so that we have something to work with.

    Regards, TMS

  9. #9
    Registered User
    Join Date
    05-08-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Pasting Excel data to Notepad

    Daily_data.xlsm

    I attached an excel file, "Daily_data.xlsm".

    Lets focus on 2 tabs, 100 and 100x.
    In the 100 tab data is populated from another program into columns A through E. I then make some changes and output to G-K.
    Tab 100x then links only to columns G-K of the 100 tab.

    I want to create a macro that takes 100x and saves it as a text file named 100x.txt.
    The macro must delete the existing 100x.txt (if it exists) before creating the new document.

    Then the whole process repeats for 101/101x, 102/102x...etc...

    Thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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