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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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