+ Reply to Thread
Results 1 to 12 of 12

Macro to copy data from excel to notepad

  1. #1
    Registered User
    Join Date
    01-05-2007
    Posts
    13

    Macro to copy data from excel to notepad

    Hi all,
    Please help I am currently stuck.
    My problem is to write a macro that will copy a range of cells like (B2: B15), auto open and paste the data to a word processor like notepad or MS word without the gridlines.

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    You cannot automate Notepad. You have two options to go directly to a text file automatically:
    1. use Excel VBA to launch Notepad, then use SendKeys command to paste
    2. use Excel VBA and the TextStream Object to output directly to a text file

    I greatly recommend option 2 over option 1. In VB Editor, do a search on the text stream object. The example code (shown below) is exactly what you need.

    Please Login or Register  to view this content.
    Another option would be to automate Word. This is similar to Option 2 above. It is a bit more complicated, though, since Word has so many more options than a simple text file.

  3. #3
    Registered User
    Join Date
    01-05-2007
    Posts
    13
    Thanks MSP77079
    The code works but how do I make the writeline syntax copy my range of excell data to the textfile.txt.
    Please help.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    I would wait for MSP77079 reply as my way you'll need to set a reference to the Microsoft Scripting RunTime Library.

    If you do want to try this then In the VBA editor, go to Tools, References, and find and check this library. Then, you can use code such as the following:

    Please Login or Register  to view this content.

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Emmamaki, the difference between what the Noob suggest and what I suggest is minor (and perhaps esoteric); namely, early vs. late binding of an object.

    Below I have taken Noob's code and shown with comments what the difference is:

    Please Login or Register  to view this content.
    Last edited by MSP77079; 01-06-2007 at 12:25 PM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Nice one MSP77079.

    VBA Noob

  7. #7
    Registered User
    Join Date
    01-05-2007
    Posts
    13
    Thanks MSP77079 and VBA Noob
    The code works perfect.
    I must confess this forum is the best in the whole wide world.
    Keep it up people.
    Thanks once again.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad you found a answer

    VBA Noob

  9. #9
    Registered User
    Join Date
    02-17-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    4

    Unhappy Re: Macro to copy data from excel to notepad

    hi... i think this is what I've been looking for a very long time..
    can I see the result? I'm looking for a macro wherein I will enter the data like a form type, after filling all the information I will click on copy button to copy all those data I entered so that when I go to my notepad and paste it will paste all the data in a nice format. is that possible? or is this macro like what I'm looking for? please help..

  10. #10
    Registered User
    Join Date
    10-15-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Macro to copy data from excel to notepad

    Hi i want to write data of each cell and row into another notepad using macro please help asap.....

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to copy data from excel to notepad

    bilal.ahmed,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  12. #12
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Macro to copy data from excel to notepad

    Quote Originally Posted by MSP77079 View Post
    Emmamaki, the difference between what the Noob suggest and what I suggest is minor (and perhaps esoteric); namely, early vs. late binding of an object.

    Below I have taken Noob's code and shown with comments what the difference is:

    Please Login or Register  to view this content.
    This is nice code, but each line has prefix like, ' Line No. so and so has value...."

    How to avoid, and just have result output, line by line?

+ 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