Hi,
I wanted to export worksheet content to text file, with save AS it is working perfectly, but it is convertin to .txt file and if i again run the macro it is throwing error "Subscript out of range" as it will not be able to find the Desired sheet.
I thr any vba code which will export the sheet content as it is.
Sheet content Sample
==============
diskLayout=[
{ part=/boot, size=512 }
{ part=/, size=16384 }
{ part=/tmp, size=20480 }
{ part=/var, size=3072 }
{ part=/usr, size=20480 }
{ part=/opt, size=10240 }
Code which i am using with SAVE AS
=======================
Dim tmpFile As String
Dim MyData As String, strData() As String
Dim entireline As String
Dim filesize As Integer
tmpFile = TempPath & Format(Now, "ddmmyyyyhhmmss") & ".txt"
Sheet2.Select
ActiveWorkbook.SaveAs Filename:=tmpFile _
, FileFormat:=xlText, CreateBackup:=False
'~~> Read the entire file in 1 Go!
Open tmpFile For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Get a free file handle
filesize = FreeFile()
'~~> Open your file
Open FlName For Output As #filesize
For i = LBound(strData) To UBound(strData)
entireline = Replace(strData(i), """", "")
'~~> Export Text
Print #filesize, entireline
Next i
Close #1
Thank you in advance
I wanted to export worksheet content to text file, with save AS it is working perfectly, but it is convertin to .txt file and if i again run the macro it is throwing error "Subscript out of range" as it will not be able to find the Desired sheet.
I thr any vba code which will export the sheet content as it is.
Sheet content Sample
==============
diskLayout=[
{ part=/boot, size=512 }
{ part=/, size=16384 }
{ part=/tmp, size=20480 }
{ part=/var, size=3072 }
{ part=/usr, size=20480 }
{ part=/opt, size=10240 }
Code which i am using with SAVE AS
=======================
Dim tmpFile As String
Dim MyData As String, strData() As String
Dim entireline As String
Dim filesize As Integer
tmpFile = TempPath & Format(Now, "ddmmyyyyhhmmss") & ".txt"
Sheet2.Select
ActiveWorkbook.SaveAs Filename:=tmpFile _
, FileFormat:=xlText, CreateBackup:=False
'~~> Read the entire file in 1 Go!
Open tmpFile For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Get a free file handle
filesize = FreeFile()
'~~> Open your file
Open FlName For Output As #filesize
For i = LBound(strData) To UBound(strData)
entireline = Replace(strData(i), """", "")
'~~> Export Text
Print #filesize, entireline
Next i
Close #1
Thank you in advance