Special characters in .txt file change during a Line Input in VBA

wdmtheman25

New Member
Joined
Feb 5, 2015
Messages
7
Hi All,
I am having issue when doing a Line Input from a text file that has special characters in it.

For example, the μ in the text below changes to μ


Here is a snippet of my code:

Do Until EOF(FF)
Line Input #1 , TextLine
TextFileArray(c) = TextLine
c = c + 1
Loop

Does anyone know how to fix this? Any help is greatly appreciated.

Thank,
Wes
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi All,
I am having issue when doing a Line Input from a text file that has special characters in it.

For example, the μ in the text below changes to μ


Here is a snippet of my code:

Do Until EOF(FF)
Line Input #1 , TextLine
TextFileArray(c) = TextLine
c = c + 1
Loop

Does anyone know how to fix this? Any help is greatly appreciated.

Thank,
Wes

I would recommend using different software to read the program. Here's example code which I might think of using if I were in your shoes (if you have ADODB.Stream)
Code:
[COLOR=#7D2727][FONT=inherit]Dim objStream, strData


Set objStream = CreateObject("ADODB.Stream")


objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("filelocation")


strData = objStream.ReadText()


objStream.Close 
Set objStream = Nothing
[/FONT][/COLOR]
 
Upvote 0
Hi RileyC,
Your suggested code worked. I was able to get the special characters to show properly in Excel. However, I need to get the special characters in Excel to show properly in Notepad (.txt file).

Here is my ultimate goal. Take a Mathcad file and import all of the Mathcad variables to Excel. Edit the variables in Excel and then send them back to Notepad. Importing the variables and special characters to Excel is now working. However, when I send the variables and special characters back to Notepad, some of the special characters don't translate properly. Any suggestion on exporting special characters?

Thanks,
Wes
 
Upvote 0
You could export the special characters UTF-8 character integer with an identifier instead of the actual character itself, as notepad might not support the special characters. Then whatever program you are using the process the notepad when it imports the data when it sees the label that it's a special character run a function to turn it into the special character again.
 
Upvote 0
What is the character encoding of your text file?
 
Upvote 0
What is the character encoding of your text file?

Below is the code that I use to create my text file. I think when I Close FF, it saves as ANSI encoding.

FF = FreeFile
Open SourceFullName3 For Output As #FF
For x = 1 To c
Print #FF , TextFileArray(x)
Next
Close FF
 
Upvote 0
It probably does. Do you want it to be ANSI encoding?
 
Upvote 0
RileyC and xenou,
Thank you so much for your help. I finally got my code to work. This is what I did.

SourceFullName3 = Replace(SourceFullName3, ".xmcd", ".txt")
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Charset = "utf-8"
objStream.Open
For x = 1 To c
objStream.WriteText TextFileArray(x)
Next

objStream.savetofile SourceFullName3, 2
objStream.Close
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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