+ Reply to Thread
Results 1 to 14 of 14

Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

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

    Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    My current macro, copies range of rows from a sheet, and puts it into Notepad.

    Please Login or Register  to view this content.

    I seek help to save the notepad file to a specific location on Drive, say C:\ABC\Note1.txt

    Each time, the notepad file would be overwritten.

    Thanks in Advance.
    Last edited by analystbank; 12-18-2014 at 01:47 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Thanks, Sixthsense,

    this worked well, but few emendations required for following reason

    Range S2:S200 value is derived using formula,

    so, in Notepad (Output file) all line for S2:S200, appears as #REF!

    Cell S1 (Header) has static text value , and output (1st line in notepad) albeit comes properly, it is inside inverted comma, at the beginning, and end, how to avoid such " "

    MOREOVER, I've about some 4-5 sheets in a workbook, and I will use this macro for each sheet to store its range value in different Text (NOTEPAD) Files.
    Last edited by analystbank; 12-18-2014 at 04:55 AM.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Replace this line

    Please Login or Register  to view this content.
    With

    Please Login or Register  to view this content.
    For me the exported notepad content is not adding any Double Quotes

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    this time, perfect, but now each rows starts, and ends with Inverted comma, ( " )


    My is Excel 2003

    Moreover, entire Workbook, looks like saved as Sheet1.txt file, so when i save macro or workbook, it prompts for this changes
    Last edited by analystbank; 12-18-2014 at 05:12 AM.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    What is your windows Version? Since I tested it in Windows XP and I am not getting any double quotes


    Quote Originally Posted by analystbank View Post
    Moreover, entire Workbook, looks like saved as Sheet1.txt file, so when i save macro or workbook, it prompts for this changes
    Not sure what you are trying to say with the above line since the macro is not written in that way...

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    OS Windows XP SP2, MS Office Version is 2003

    Once i run the macro, it properly exports text to notepad, and saves at desired location on the drive, but with quotes (" ) at the begining, and end of each line.

    Once the job is done, i want to close the Excel Workbook, and observe that Workbook name is changed to Sheet1 name, and it prompts that since the workbook has multiple sheets, it can not save in .txt format

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Try this final version of code

    Please Login or Register  to view this content.

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Runtime Error 1004,

    Method 'Saveas' of Object'_workbook' failed

    on this line

    Please Login or Register  to view this content.

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Change the file format from

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    modified, per your suggest to FileFormat:=xlUnicodeText,


    but still same error 1004....

    Sample file is attached. Currently working on sheet M
    Attached Files Attached Files
    Last edited by analystbank; 12-19-2014 at 01:29 AM.

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Hi analystbank
    Here's my version Try this
    Please Login or Register  to view this content.

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    Thanks a ton. @YAsser,

    Wonderful. Done

    A suitable modification, in line

    Please Login or Register  to view this content.
    like Set Rng = Sheets("M").Rang.Selection.End(xlDown)).Select

    in order to ensure, that whatever is the end, instead of S200, only that much would be taken from S1
    Last edited by analystbank; 12-19-2014 at 05:13 AM.

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

    Re: Save Notepad through VBA Macro, having Copied Range of Cells, Pasted into notepad

    I replaced the Set RNg line to

    Please Login or Register  to view this content.
    and it worked well. Thanks all.

+ 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. Opening Notepad a saved notepad file and copying the data on it
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2014, 06:18 PM
  2. Replies: 1
    Last Post: 01-14-2014, 04:18 PM
  3. Remove marching ants after notepad macro opens notepad
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-07-2014, 09:47 PM
  4. how to copy selected notepad text and paste it in other notepad with macro
    By Guru232 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 04-24-2013, 04:43 AM
  5. [SOLVED] Macro to export range of cells to notepad file.
    By MrIdontknowexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2012, 03:17 PM

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