davewatson86
New Member
- Joined
- Jul 8, 2019
- Messages
- 30
G'Day all
i am trying to loop through some worksheets and export the data into a txt file.
the below code works but i need it to save the file in the specified location rather than open it.
anyone able to help me out?
many thanks
Dave
i am trying to loop through some worksheets and export the data into a txt file.
the below code works but i need it to save the file in the specified location rather than open it.
anyone able to help me out?
many thanks
Dave
Code:
Sub CrText()
Dim c00 As Variant
Dim textFilePath, File_Name As String
Dim lngCounter As Long
Dim FF As Integer
i = 1
Do Until i = 13
If i = 1 Then Set WS = WS_1_Con
If i = 1 Then File_Name = WS_Admin.Range("C2").Value & "1C"
If i = 2 Then Set WS = WS_1_FCon
If i = 2 Then File_Name = WS_Admin.Range("C2").Value & "1F"
If i = 3 Then Set WS = WS_2_Con
If i = 3 Then File_Name = WS_Admin.Range("C2").Value & "2C"
If i = 4 Then Set WS = WS_2_FCon
If i = 4 Then File_Name = WS_Admin.Range("C2").Value & "2F"
If i = 5 Then Set WS = WS_3_Con
If i = 5 Then File_Name = WS_Admin.Range("C2").Value & "3C"
If i = 6 Then Set WS = WS_3_FCon
If i = 6 Then File_Name = WS_Admin.Range("C2").Value & "3F"
If i = 7 Then Set WS = WS_4_Con
If i = 7 Then File_Name = WS_Admin.Range("C2").Value & "4C"
If i = 8 Then Set WS = WS_4_FCon
If i = 8 Then File_Name = WS_Admin.Range("C2").Value & "4F"
If i = 9 Then Set WS = WS_5_Con
If i = 9 Then File_Name = WS_Admin.Range("C2").Value & "5C"
If i = 10 Then Set WS = WS_5_FCon
If i = 10 Then File_Name = WS_Admin.Range("C2").Value & "5F"
If i = 11 Then Set WS = WS_6_Con
If i = 11 Then File_Name = WS_Admin.Range("C2").Value & "6C"
If i = 12 Then Set WS = WS_6_FCon
If i = 12 Then File_Name = WS_Admin.Range("C2").Value & "6F"
textFilePath = CStr(VBA.CurDir) & "\" & File_Name & ".txt"
WS.Activate
FF = VBA.FreeFile
c00 = Range("A3", Range("A" & Rows.Count).End(xlUp).Offset(0, 14))
Open textFilePath For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL]
For lngCounter = LBound(c00, 1) To UBound(c00, 1)
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL] , Join(Application.Index(c00, lngCounter, 0), "|")
Next
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL]
Shell "C:\WINDOWS\notepad.exe " & textFilePath, vbNormalFocus
i = i + 1
Loop
End Sub