Need to export to text results not formula

M

Muaitai

I need to export only the results to a text file not the formulas.
I have vlookups that when I export the formula goes to the text file
but instead I need only the results of the query.
I am usnig the following macro:

Public Sub SaveAsTXT()
fileSaveName = Application.GetSaveAsFilename( _
FileFilter:="Text Files (*.txt), *.txt")
If fileSaveName <> False Then
MsgBox "Save as " & fileSaveName
End If
End Sub

Thank you,

Muaitai
 
G

Guest

I think maybe the easiest way to do this is to kind of start over. The code
you have will save the entire workbook, just renamed with a .txt extension
instead of a .xls extension.

Try using some code similar to this, lets assume you want to save the
information on rows 1 through 50 on a sheet in .txt format (and there are
several to choose from), this is for MS-DOS text, no delimiters:

Sub SaveDataAsText()
Rows("1:50").Select
ActiveWorkbook.SaveAs Filename:="G:\ExcelHelp_21June2006.txt", _
FileFormat:=xlTextMSDOS
End Sub

Now that has the filename hard coded, you could use other code to get a
filename from the user or yourself.

If we change things a little, it all can be done in a single macro

Sub SaveDataAsText()
Dim fName As Variant
Rows("1:50").Select

fName = Application.GetSaveAsFilename( _
fileFilter:="MS-DOS text files (*.txt), *.txt")
If fName = "" Then ' user [Cancel]ed
Exit Sub
End If

On Error Resume Next
ActiveWorkbook.SaveAs Filename:=fName, _
FileFormat:=xlTextMSDOS If Err <> 0 Then
'user probably cancelled at this point
'as when notified of existing file of same name
'you can either test for errors
'or simply ignore them
Err.Clear
End If
 
D

Dave Peterson

You have a response at your first post.
I need to export only the results to a text file not the formulas.
I have vlookups that when I export the formula goes to the text file
but instead I need only the results of the query.
I am usnig the following macro:

Public Sub SaveAsTXT()
fileSaveName = Application.GetSaveAsFilename( _
FileFilter:="Text Files (*.txt), *.txt")
If fileSaveName <> False Then
MsgBox "Save as " & fileSaveName
End If
End Sub

Thank you,

Muaitai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top