Macro sends data to text file but errors out with special characters.

rimshot609

Board Regular
Joined
Jun 4, 2015
Messages
79
I am using this Macro that copies the data in column B
and saves it to a text file with the titles in column C and if there is no text in the cells in column B it creates an emtpy text file. It works great but if the cells have special characters it gives me an error. Any suggestions?


Code:
Sub SendToText()
    Dim cell As Range
    Dim FF As Long
    Dim Counter As Long
    
    For Each cell In Range("B1", Range("C" & Rows.Count).End(xlUp))
        If cell.Value <> "" Then
            FF = FreeFile()
            Open ThisWorkbook.Path & "\" & cell.Value & ".txt" For Output As #FF
            Print #FF, cell.Offset(, 1).Text
            Close #FF
            Counter = Counter + 1
        End If
    Next cell
    
    MsgBox Counter & " - Files sent.", , "Text files created"
 
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top