VBA copying a range from Excel and pasting to a text file

5 pts.
Tags:
Excel VBA
Microsoft Excel
VBA
Do you know how to copy from excel and paste to a text file using VBA?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello Dear,

Try using the code below. I am sure this will help you

Regards,
Sarfaraz Ahmed

Sub CopyPaste()

Dim i As Long
Dim j As Integer

i = 1
j = 1
Open "C:\Test1.txt" For Append As #1
Do While i <= Selection.Rows.Count
j = 1
Do While j <= Selection.Columns.Count

Print #1, Selection.Cells(i, j);

j = j + 1
Loop
Print #1, vbCrLf
i = i + 1
Loop
Close #1

End Sub

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • 1200s
    Hi there are 2 issue 1 there is a line spacing how to fix 2 if there is a Time like 09:30 then i get 4091.334 Sri
    10 pointsBadges:
    report
  • Shiva190
    This works perfectly right but we are getting space between the records in text file.
    10 pointsBadges:
    report
  • ToddN2000
    @shiva190: 
    If you are getting the space between the lines it's because of the
      
    vbCrLf

    That is for a carriage return and a line feed try using 

    vbCr
    131,380 pointsBadges:
    report
  • subhadrahassanrajan
    Dear Team,
    How to copy the data from excel to notepad without using send key option.
    example: in excel its available in A2, B2, C2, D2
    but i need the output in differnt format...
    Output: A2
    B2
    C2
    D2

    like this i need output one below another.
    Kindly help me
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: