+ Reply to Thread
Results 1 to 4 of 4

Unable to copy and paste a text file into excel

Hybrid View

  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    67

    Unable to copy and paste a text file into excel

    Hi all,

    i am trying to open multiple text files, copy and paste in single excel sheet ( one by one). i am use below code it open all the text file into excel but unable to copy and paste in single excel sheet. can any one help..

    Sub loopyarray()
    
       Dim filenames As Variant
    
       ' set the array to a variable and the True is for multi-select
       filenames = Application.GetOpenFilename(, , , , True)
    
          counter = 1
    
          ' ubound determines how many items in the array
          While counter <= UBound(filenames)
    
             'Opens the selected files
             Workbooks.Open filenames(counter)
    
             ' displays file name in a message box
             MsgBox filenames(counter)
    
             'increment counter
             counter = counter + 1
             
    
          Wend
       End Sub

    Thanks

    Jack
    Last edited by arlu1201; 07-23-2012 at 03:53 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: Unable to copy and paste a text file into excel

    I always have to convert TXT into XLS before i can import it into excel.

    name file.txt as file.xls

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

    Re: Unable to copy and paste a text file into excel

    Jack40,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature.
    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]

  4. #4
    Registered User
    Join Date
    07-19-2012
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    67

    Re: Unable to copy and paste a text file into excel

    Hi all,

    Here is the code for copy data from mulitple text file and paste in single sheet..

    Sub Button1_Click()
       Dim filenames As Variant
       Application.DisplayAlerts = False
       ' set the array to a variable and the True is for multi-select
       filenames = Application.GetOpenFilename(, , , , True)
       counter = 1
    ' ubound determines how many items in the array
          While counter <= UBound(filenames)
    
           'Opens the selected files
             Workbooks.Open filenames(counter)
             ActiveWindow.Activate
             Range("A1").Select
             Range(Selection, Selection.End(xlDown)).Select
             Selection.Copy
             Windows("cONVERT.xlsm").Activate
             Sheets("Report").Select
             ActiveSheet.Paste
             Range("A1").Select
             Selection.End(xlDown).Select
             ActiveCell.Offset(1, 0).Activate
             ActiveWindow.ActivateNext
             ActiveWindow.Close
             Application.DisplayAlerts = False
             ' displays file name in a message box
             'MsgBox filenames(counter)
    
             'increment counter
             counter = counter + 1
         Wend
       End Sub

    Regards

    Jack

+ 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