2016-08-15 13 views
0

で作業していないスクリプトを置き換えます。私はテキストファイルにコンマですべてのタブを置き換えるために、次のコードを使用しようとしていますUnicodeのTXTファイル

Const ForReading = 1 
Const ForWriting = 2 
Const TristateTrue = -1 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile("C:\Users\Tom\Desktop\CSV.txt", ForReading, TristateTrue) 

strText = objFile.ReadAll 
strTab = vbTab 

strText = Replace(strText, strTab, ",") 

objFile.Close 

Set objFile = objFSO.OpenTextFile("C:\Users\Tom\Desktop\CSV.txt", ForWriting, TristateTrue) 

objFile.Write strText 

objFile.Close 

添付fileのためにこれを実行している場合しかし、私が手エラー:

ライン17 シャア1 無効なプロシージャ呼び出しまたは引数

このファイルはExcelから作成されたUnicodeのtxtファイルです。

ファイルを開いてUTF-8形式で保存すると、コードが正常に動作します。しかし、私はコードでこの変換を行う方法を見つけることができません。

オリジナルのユニコードテキストファイルで作業するコードを手に入れることができますか、実行可能コード(vba/batch)を使用してファイルをUTF-8に変換する方法を見つけることができますか?ヘルプ

Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.

object.OpenTextFile(filename[, iomode[, create[, format]]])

object

Required. Object is always the name of a FileSystemObject.

filename

Required. String expression that identifies the file to open.

iomode

Optional. Can be one of three constants: ForReading, ForWriting, or ForAppending.

create

Optional. Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created, False if it isn't created. If omitted, a new file isn't created.

format

Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.

から

答えて

1

あなたはTristateTrueないFormatCreateを指定しています。

以下のFalseを省略することができます(デフォルトはFalse)が、,ではありません。位置パラメータは、順番に指定する必要があります。欠落するパラメータはカンマで指定します。末尾のカンマも省略できます。

objFSO.OpenTextFile("C:\Users\Tom\Desktop\CSV.txt", ForWriting, False, TristateTrue)

+0

うわー、私はそれを逃した、ありがとう!私はそれがブール値ではないので、CreateでTristateTrueがエラーを投げたと思ったでしょうか?それは今でも完璧に動作しますが、問題ありません。 – Tom

関連する問題