linuxConvert
05-12-2008, 06:06 AM
Hello,
I have been looking all over for a new way to do this and cant find it. So here it goes...
I have a workbook with about 20 tabs. They all contain data that starts in cell "B6" and can be in any cell down and to the right from there.
Here is the macro to select all of the data on that workbook:
Sub FileExport(wsName As String, CellBegin As String, FilePathName As String, DownAndRight As Boolean)
'
' FileExport(...)- exports input data sheets to ascii text files - extensively used.
'
Dim ws As Worksheet
Dim RangeStart As String
Dim RangeEnd As String
Set ws = Worksheets(wsName)
ws.Activate
ws.Range(CellBegin).Select
RangeStart = ActiveCell.Address
If DownAndRight = True Then
RangeEnd = ActiveCell.SpecialCells(xlCellTypeLastCell).Address
Else
RangeEnd = ActiveCell.End(xlDown).Address
End If
ws.Range(RangeStart & ":" & RangeEnd).Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.SaveAs FileName:=FilePathName, FileFormat:=xlText, CreateBackup:=False
ActiveWindow.Close
ws.Activate
Range("A3").Select
End Sub
I need to save that copied data to a file called "something.dat". As you can see by the macro, it opens a new Workbook an then saves it. This takes some time and I am trying to remove the open workbook step. Any way to save copied data directly to a file?
EDIT: Would a OpenAsTextStream be what I want?
Thanks in advance!
-linuxConvert
I have been looking all over for a new way to do this and cant find it. So here it goes...
I have a workbook with about 20 tabs. They all contain data that starts in cell "B6" and can be in any cell down and to the right from there.
Here is the macro to select all of the data on that workbook:
Sub FileExport(wsName As String, CellBegin As String, FilePathName As String, DownAndRight As Boolean)
'
' FileExport(...)- exports input data sheets to ascii text files - extensively used.
'
Dim ws As Worksheet
Dim RangeStart As String
Dim RangeEnd As String
Set ws = Worksheets(wsName)
ws.Activate
ws.Range(CellBegin).Select
RangeStart = ActiveCell.Address
If DownAndRight = True Then
RangeEnd = ActiveCell.SpecialCells(xlCellTypeLastCell).Address
Else
RangeEnd = ActiveCell.End(xlDown).Address
End If
ws.Range(RangeStart & ":" & RangeEnd).Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.SaveAs FileName:=FilePathName, FileFormat:=xlText, CreateBackup:=False
ActiveWindow.Close
ws.Activate
Range("A3").Select
End Sub
I need to save that copied data to a file called "something.dat". As you can see by the macro, it opens a new Workbook an then saves it. This takes some time and I am trying to remove the open workbook step. Any way to save copied data directly to a file?
EDIT: Would a OpenAsTextStream be what I want?
Thanks in advance!
-linuxConvert