VBA: Convert spreadsheet to .txt file

iand5

New Member
Joined
Jul 26, 2017
Messages
36
Hi, I currently have the following code to convert a spreadsheet into a .txt file:

Code:
Sub Macro1()


'Saves the Activesheet to the Desktop as a text file with a different extension
Dim newFile As String, fName As String, gName, fileSaveName
    gName = "FGM_"
    fName = Range("A2").Value
    newFile = gName & " " & fName & " " & Format$(Date, "dd-mm-yyyy")
    fileSaveName = Application.GetSaveAsFilename(newFile, "Text (MS-DOS) (*.txt), *.txt")
    ThisWorkbook.SaveAs fileSaveName, xlTextMSDOS
End Sub

My spreadsheet is filtered so that only certain values are displayed. Whenever I run the macro it converts the spreadsheet into a .txt file. The problem is that the .txt file contains the cells that are hidden.

Is there a possible way to convert a spreadsheet into a .txt file that only displays filtered values?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I don't think the .SaveAs allows you to select filtered and non-filtered values.
A possible alternative is to copy/pastespecial your spreadsheet into a new one and then apply the .SaveAs [name], xlTextMSDOS
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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