VB Macro Help Needed - Exporting a Range to .txt with save name as cell value

Jacksoner

New Member
Joined
Aug 1, 2018
Messages
2
Objective: I want to export a known range of Cells to a .txt file with the click of a command button. I want the file to be automatically saved with the name as the value of a cell (A12)

I already did some research and was able to slightly change an existing code I found that someone created to export the range to a .txt. However the name is not based on the value of Cell A12. I believe this is an easy thing to do, but I know absolutely nothing about Visual Basic.

This is my Existing Code I am using for the Command Button:

Code:
Private Sub CommandButton1_Click()
Dim c As Range, r As Range
Dim output As String
For Each r In Range("AR8:AR211").Rows
For Each c In r.Cells
output = output & c.Value
Next c
output = output & vbNewLine
Next r
Open "C:\Users\Owner\Documents\RenameToParcel.txt" For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , output
Close
End Sub


Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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
Back
Top