PDA

View Full Version : Exporting to c:\test.txt problems



ramonhasbun
04-11-2008, 09:40 AM
Good day,
I am having a problem exporting an excel sheet to text file,
in some computers with windows vista I hace disabled User Control, and it worked like a charm,
now I have one computer with windows xp, office 2003 that doesn't export
what may be causing the problem

tx

RichardSchollar
04-11-2008, 10:38 AM
Hi

How exactly are you performing the export? Does it involve code? If so, please post the code you are using :)

Richard

ramonhasbun
04-11-2008, 01:58 PM
I got this code from a cpearson site, cant psate link cause haven't got the post counts, got to give the credit where its due
cpearson.com/excel/ImpText.aspx (http://www.cpearson.com/excel/ImpText.aspx)
----------------------------------------------------------------------


Sub DoTheExport()
ExportToTextFile FName:="C:\PdN" & Hoja1.Cells(10, 13) & Hoja1.Cells(11, 13)" & _
"& Hoja1.Cells(12, 13) & "_V" & Hoja1.Cells(13, 13) & ".txt", Sep:=";", _
SelectionOnly:=False, AppendData:=True
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Sub ExportToTextFile(FName As String, _
Sep As String, SelectionOnly As Boolean, _
AppendData As Boolean)
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If
If AppendData = True Then
Open FName For Append Access Write As #FNum
Else
Open FName For Output Access Write As #FNum
End If
For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = VBA.Chr(34) & VBA.Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = VBA.Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' END ExportTextFile
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

TheAntiGates
04-11-2008, 06:35 PM
Determine if you have root file creation privilege. On this XP machine I'm typing on, I must log in as administrator to create a file in \ .