Public Sub ExportFile2()
'Created by Dragon Wood (September, 2011)
'Exports the data to a .csv file and puts directly on the C drive
Application.ScreenUpdating = False
With Sheets("Sheet2")
.Unprotect Password:="Password"
Dim intExport As Integer
Dim LR As Long
Dim i As Long
Dim strFile As String
strFile = "C:\file2.csv"
'strFile = ThisWorkbook.Path & "\" & "file2.csv"
LR = Range("A" & Rows.Count).End(xlUp).Row
intExport = FreeFile
Open strFile For Output As #intExport
For i = 4 To LR
Print #intExport, .Range("A" & i).Value; & ","; .Range("B" & i).Value; & ","; .Range("C" & i).Value; & ","; .Range("D" & i).Value; & ","; .Range("E" & i).Value; & ","; .Range("F" & i).Value; & ","; .Range("G" & i).Value; & ","; .Range("H" & i).Value; & ","; .Range("I" & i).Value; & ","; .Range("J" & i).Value
Next i
Close #intExport
.Protect Password:="Password"
End With
Application.ScreenUpdating = True
End Sub
Public Sub ExportFile2()
'Created by Dragon Wood (September, 2011)
'Exports the data to a .csv file and puts directly on the C drive
Application.ScreenUpdating = False
With Sheets("Sheet2")
'.Unprotect Password:="Password"
Dim intExport As Integer
Dim LR As Long
Dim i As Long
Dim strFile As String
strFile = "C:\file2.csv"
'strFile = ThisWorkbook.Path & "\" & "file2.csv"
LR = Range("A" & Rows.Count).End(xlUp).Row
intExport = FreeFile
Open strFile For Output As #intExport
For i = 4 To LR
Print #intExport, .Range("A" & i).Value; ","; .Range("B" & i).Value; ","; .Range("C" & i).Value; ","; .Range("D" & i).Value; ","; .Range("E" & i).Value; ","; .Range("F" & i).Value; ","; .Range("G" & i).Value; ","; .Range("H" & i).Value; ","; .Range("I" & i).Value; ","; .Range("J" & i).Value
Next i
Close #intExport
'.Protect Password:="Password"
End With
Application.ScreenUpdating = True
End Sub
Ok, this one is tested and works.
Code:Public Sub ExportFile2() 'Created by Dragon Wood (September, 2011) 'Exports the data to a .csv file and puts directly on the C drive Application.ScreenUpdating = False With Sheets("Sheet2") '.Unprotect Password:="Password" Dim intExport As Integer Dim LR As Long Dim i As Long Dim strFile As String strFile = "C:\file2.csv" 'strFile = ThisWorkbook.Path & "\" & "file2.csv" LR = Range("A" & Rows.Count).End(xlUp).Row intExport = FreeFile Open strFile For Output As #intExport For i = 4 To LR Print #intExport, .Range("A" & i).Value; ","; .Range("B" & i).Value; ","; .Range("C" & i).Value; ","; .Range("D" & i).Value; ","; .Range("E" & i).Value; ","; .Range("F" & i).Value; ","; .Range("G" & i).Value; ","; .Range("H" & i).Value; ","; .Range("I" & i).Value; ","; .Range("J" & i).Value Next i Close #intExport '.Protect Password:="Password" End With Application.ScreenUpdating = True End Sub