Tool for getting data

  • Thread starter Thread starter Alberto Brivio
  • Start date Start date
A

Alberto Brivio

Dear All,

I'm searching for a tool able to get data from a specific worksheet (
columns and rows selectable too) , and those data should be written into an
ascii file.




Regards


Alberto Brivio
 
Not possible with worksheet functions, but a macro would
do this for you. Presuming you want a tab delimited text
file, try this:

Sub Range_to_TextFile()
Dim rngR As Range
Dim strFile As String
Dim wsW As Worksheet

On Error Resume Next
Set rngR = Application.InputBox(prompt:="Select range of
cells to exprt to text file:", _
Title:="Range to Text
File", Type:=8)
On Error GoTo 0
If rngR Is Nothing Then Exit Sub
If rngR.Areas.Count > 1 Then
MsgBox prompt:="Range must contain one area only!", _
Title:="Range to Text File", _
Buttons:=vbExclamation
Exit Sub
End If

strFile = Application.GetSaveAsFilename
(initialfilename:="*.txt", _
filefilter:="Text Files
(*.txt), *.txt,All Files (*.*),*.*")
If strFile = "False" Then Exit Sub
Application.ScreenUpdating = False
Set wsW = Application.Workbooks.Add.Sheets(1)
rngR.Copy Destination:=wsW.Cells(1)
wsW.SaveAs Filename:=strFile, FileFormat:=xlTextMSDOS
wsW.Parent.Close savechanges:=False
Application.ScreenUpdating = True
End Sub

Cheers,
Dave.
 
Back
Top