+ Reply to Thread
Results 1 to 16 of 16

VB Code to copy and paste text file into excel.

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to copy and paste text file into excel.

    Hello:

    I have a file "09-05-2017-Menu Item Sales.Rep" in C:\Store1\.
    Although this file has extention .REP, I open it with Notepad without any issue.

    I need VB code to copy the content of this file in excel workbook "Sheet1" at Cell A1.

    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: VB Code to copy and paste text file into excel.

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    Try this:
    Please Login or Register  to view this content.
    It opens up a new file - not sure if this brings in the data in the way you want
    Last edited by kev_; 09-06-2017 at 10:42 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello kareDog:

    I get the error as atatched..
    Please help.
    Thanks
    Attached Images Attached Images

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello kev:

    Your code opens the file but now it needs to be pasted in current file at location A1.
    Once pasted then close REP file.
    Please help, let me know if any questions.
    Thanks
    Riz
    Last edited by rizmomin; 09-06-2017 at 11:20 AM.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    Try:
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello Kev:

    Thanks a lot and below is little modified code i am using and it works.
    Now i need a code added so that once the data is pasted from "fName" the need to CLOSE File "FName".

    Please Login or Register  to view this content.
    Please let me know if any questions.
    Thanks
    Riz
    Last edited by rizmomin; 09-06-2017 at 01:23 PM.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    Is this what you want?
    - you did not include word "Closed" in your question - so I am guessing..

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello:

    I forget to mention that i need code to close the file from which the data is pasted.
    Thanks

    Riz

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello kev_

    Yes, i tried using
    Please Login or Register  to view this content.
    This closes the file which i am running the macro from.
    The file which data is pasted from stays open.
    Please let me know if you have any questions.
    Thanks.

    Riz

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    Did you try the whole code EXACTLY as modified by me?
    I amended more than one line...

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello kev_

    Yes i am using the code exactly like how you have.
    Please let me know if you have any questions.
    Thanks.

    R

  13. #13
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    I have no questions
    - you have modified what I gave you in post#6 and changed the order of some of the items
    - the correct file was closing before you modified the code
    - you broke it so you fix it

    I suggest you start again with post#6 and modify everything one step at a time and test it
    - keep the sequence of events the same

  14. #14
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: VB Code to copy and paste text file into excel.

    Hi Riz,

    After googling it for a bit, found out that the method on post #2 is not worked for Windows 8 and 10 :
    https://stackoverflow.com/questions/...ndows-10-issue
    http://www.spreadsheet1.com/how-to-c...excel-vba.html
    https://www.experts-exchange.com/que...s-working.html

    so please this code instead :
    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste text file into excel.

    Hello Guys:

    I got it resolved by using Kev_ coding and added
    Please Login or Register  to view this content.
    Basically before above event i close THISWORKBOOK.
    Works the way i wanted.

    Thanks a lot for all the help..

    Riz

  16. #16
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VB Code to copy and paste text file into excel.

    Glad you found a solution. Thanks for the rep

+ 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. Copy Visible Range in Excel and Paste into Text File
    By jpv5 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-14-2016, 09:15 AM
  2. [SOLVED] VB Code to copy data from excel to text file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2015, 01:56 PM
  3. [SOLVED] VB Code to copy and paste from all text file and paste into single file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-29-2015, 06:00 PM
  4. Replies: 2
    Last Post: 10-29-2014, 10:23 AM
  5. [SOLVED] VBA code to open many files, copy text, close file, paste text in second work
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-11-2014, 12:59 PM
  6. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  7. [SOLVED] Unable to copy and paste a text file into excel
    By Jack40 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2012, 10:53 PM

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