Sending Data To A Text File

JonRowland

Active Member
Joined
May 9, 2003
Messages
376
Office Version
  1. 365
Platform
  1. Windows
Can anyone help, I can't seem to find an easy solution.

I am looking to have a macro that will select copy some text and then send it into a text file.

What VBA would I need to open and paste into the text file?

Cheers

Jon
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

JonRowland

Active Member
Joined
May 9, 2003
Messages
376
Office Version
  1. 365
Platform
  1. Windows
I'm sending this to the top in case those state side missed it and coudl help
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Jon

I'm sure it's possible but some further details could be helpful.
 

JonRowland

Active Member
Joined
May 9, 2003
Messages
376
Office Version
  1. 365
Platform
  1. Windows
Hi,

I try my best as explaining what I am looking to do.

The user enters some text.
The text entered is user to create some SQL for a database query. Currently this is copied out manually into a SQL import file which contains some other SQL needed to the query.
What I want is for Excel to output column C into a text file, saving on the user from manually copying it.

Hope that's clear.

Jon
 

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,345
try this or adapt to suit
Code:
Sub write_to_file()
Dim f As Integer
f = FreeFile
fname = "c:\youfile.txt" ' change to suit
   Open fname For Output As f
   c = 3
   r = 1
   Do Until IsEmpty(Cells(r, c))
          Write #f, Cells(r, c)
        r = r + 1
        Loop
         Close #f
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,496
Messages
5,596,494
Members
414,071
Latest member
hijackhippo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top