+ Reply to Thread
Results 1 to 13 of 13

Vba copy text file without open it

  1. #1
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Vba copy text file without open it

    Hi,

    I am using below code to open and copy entire a text file from a folder, is it a way to copy the file without opening the text file in notepad?

    Shell "Notepad d:\1_txtfile\" & txtfile & ".txt", vbNormalFocus

    Would appreciate help from anyone.

    Thanks

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Vba copy text file without open it

    Data import...
    See
    https://support.office.com/en-us/art...b-339e391393ba

  3. #3
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Vba copy text file without open it

    I'm not entirely sure what you are asking, but hope this can help. This will put the contents of the text file into the variable FileData.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Re: Vba copy text file without open it

    Jindon,
    Thanks for sharing, but i need to work in different way
    Last edited by chhiew; 10-01-2018 at 11:00 PM.

  5. #5
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Re: Vba copy text file without open it

    mgs73,
    Thanks for sharing, i want to open and copy the text file data, normally i got to open text file with notepad, then copy them on clipboard and close the notepad.

    So my question is can i do this without open the close notepad.exe? something like disable screen updating and make it invisible.

    Thanks

  6. #6
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Vba copy text file without open it

    The code I posted won't open notepad. It will open the file, but not in a way that is visible to the user.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Vba copy text file without open it

    What's your problem?

    Both suggestions will not open the file.

  8. #8
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Re: Vba copy text file without open it

    Jindon, sorry for late reply, been busy last two days. yes just got you both code not open the file, thank you!

    i got 2 more questions:
    1)what if the file contain utf-8 character? how to show them in msgbox ? as it shows many chracter like this " Ÿ“Ÿ“ *九œˆ"

    2) i want to import the text file to textbox by using code : Worksheets("Sheet1").TextBox1.Text = txt, but not working, any idea what went wrong?


    Thank you

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Vba copy text file without open it

    I don't think you can use textbox on the sheet.
    Prepare userform(name UserForm1) with 1 x textbox(name TextBox1)
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Re: Vba copy text file without open it

    Jindo, thanks for your help, it work great! appreciate your help!

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Vba copy text file without open it

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  12. #12
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Vba copy text file without open it

    Nice Solution Jindon Sir

  13. #13
    Registered User
    Join Date
    07-09-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010 64bit
    Posts
    48

    Re: Vba copy text file without open it

    Thank you Jindon!

+ 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. Open a Text File that is named in another cell, copy and paste all in another tab
    By Bobbbo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-17-2016, 04:16 PM
  2. Open a new file when clicking a cell, and copy text
    By mariur89 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-17-2015, 05:58 PM
  3. [SOLVED] Open text file and copy specific rows into spreadsheet column
    By larsahl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-17-2014, 07:02 AM
  4. [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
  5. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  6. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  7. looping, Open text file, copy text, close text file
    By jwilds1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2009, 05:12 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