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

5 pts.
Tags:
Excel VBA
Microsoft Excel
VBA
Visual Basic for Applications
Do you know how to copy from excel and paste to a text file using VBA?
ASKED: May 27, 2009  9:38 PM
UPDATED: February 2, 2012  11:36 AM

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
<a href=”http://findsarfaraz.blogspot.com”>MS Excel help</a>

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: 1  Reply

 
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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • 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

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following