Conversion of special characters

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,382
Office Version
  1. 2021
Platform
  1. Windows
I have an Excel tool that plays my mp3 files (like a jukebox, but far more sophisticated).
It currently relies on an Access database for its function, but I am in the process of
converting it so that it does not rely on Access. To this end, I have converted all of the
Access tables into text files (.txt extension). The tool then reads data from text files
rather than from Access tables. All tables have therefore been converted to text files using the
Print statement in VB eg
''''''''''''''''
VBA Code:
Open "C:\users\peter\data\text_files\test.txt" For Output As #ff
Set cnt = CreateObject("ADODB.Connection")
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strdb & ";" & _
"Jet OLEDB:Database Password=" & pw & ";"

strSql = "Select * from [thetable] order by ID;"
rst.Open strSql, cnt, adOpenStatic
rst.MoveFirst
While Not rst.EOF
mytext = vbNullString
For y = 1 To 11 ' number of fields in this table
mytext = mytext & Trim(rst(y - 1)) & "|"
Next y
Print #ff, Left(mytext, Len(mytext) - 1)
rst.MoveNext
Wend
rst.Close
Close #ff
Code:
''''''''''''''
This creates records in the text file such as:
C:\Users\Peter\mp3\RPMellow\Alison Krauss\ðOh, Atlanta.mp3|

However, during this process, some special characters get changed. This means that when the file is read
back into the Excel tool, the filenames have effectively changed, and the tool doesn't work as intended.
I can overcome this by using a 'Find and replace' routine when reading the files back, but I would like to
know if there is a way of preserving the files' correct names and avoiding the special character conversion

This is how it is stored in Access:
C:\Users\Peter\mp3\RPMellow\Alison Krauss\¥Oh, Atlanta.mp3
C:\Users\Peter\mp3\RPMellow\Alison Krauss & Gillian Welch\©I'll Fly Away.mp3


This is how it looks in the text file (note special characters have been altered)
C:\Users\Peter\mp3\RPMellow\Alison Krauss\ðOh, Atlanta.mp3|
C:\Users\Peter\mp3\RPMellow\Alison Krauss & Gillian Welch\½I'll Fly Away.mp3|

This is how it looks when read back into Excel
C:\Users\Peter\mp3\RPMellow\Alison Krauss\ðOh, Atlanta.mp3
C:\Users\Peter\mp3\RPMellow\Alison Krauss & Gillian Welch\½I'll Fly Away.mp3


(NB the special characters in the filenames are used to trigger certain functionality in the Excel tool)




Can anyone advise on how to retain the filenames without conversion of those characters?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe...
I miss some code though because you posted not all of it

VBA Code:
Sub test()
 Dim cnt As Object, strSql, y As Long
 
 Set cnt = CreateObject("ADODB.Connection")
 cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strdb & ";" & "Jet OLEDB:Database Password=" & pw & ";"
 strSql = "Select * from [thetable] order by ID;"
 rst.Open strSql, cnt, adOpenStatic
 
 With CreateObject("scripting.filesystemobject").createtextfile("C:\users\peter\data\text_files\test.txt", True, True)
   While Not rst.EOF
     mytext = ""
     For y = 1 To 11 ' number of fields in this table
       mytext = mytext & Trim(rst(y - 1)) & "|"
     Next
     .writeline Left(mytext, Len(mytext) - 1)
     rst.MoveNext
   Wend
 End With
 rst.Close
End Sub
 
Last edited:
Upvote 0
Solution
Thanks for prompt reply. I will try this and repost the results ( tomorrow).
Regards
 
Upvote 0
While reading the data into Excel, you should open the textfile like

VBA Code:
.OpenTextFile("C:\users\peter\data\text_files\test.txt", 2, True, -1)
 
Upvote 0
Thanks for your reply. I will try this and report back.(tomorrow)
 
Upvote 0
I have used this code and it works perfectly. Thank you so much!
 
Upvote 0
You’re welcome! Cheers
 
Upvote 0

Forum statistics

Threads
1,223,872
Messages
6,175,104
Members
452,613
Latest member
amorehouse

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