Reputation: 387
I have been writing a vbs script in notepad that adds text to an excel file, and this is working fine.
I then needed to write unicode characters to the excel file, so saved the vbs file as unicode and again all worked fine.
I am noe trying to write the file dynamically from another program, which is possible, but it writes the unicode vbs file as utf-8 formatting, and then when I try to run the vbs file, it gives an error saying error:invalid character code:800A0408 Source:microsoft VBScript compilation error
Does this mean I cannot run a file saved as utf-8 formatting, or am I missing something?
Any help would be gratefully received!
Dave
Upvotes: 1
Views: 3596
Reputation: 31
Use UCS-2 Little Endian, that accepts unicode chars and runs VBS properly! You can convert any existing VBS file to this format with notepad++ for example.
Upvotes: 3
Reputation: 38745
C/WScript.exe can't run UTF-8 encoded .vbs files. If you can't change the encoding/write mode of that 'another program', you either have to convert the UTF-8 source to UTF-16 or write/generate the code in plain ASCII and inject the unicode data via ChrW() resp. an UTF-16 (easy) or UTF-8 (ADODB.Stream) encoded external file.
WRT comment:
As long as you don't use non-ascii characters in string literals - and you can avoid that for a few of them by using ".." & ChrW(..) & ".." - you can save the .vbs as ascii. If your 'another program' loads and saves such a file as UTF-8 (without BOM!) it doesn't matter; but if it adds a BOM you must convert the source file.
Perhaps you should add some more details/code to improve your chances of getting better advice.
Upvotes: 2