型定義(Excel・VBA)
Scripting・VBScript・ADODB
Microsoft Scripting Runtime(FileSystemObject・Dictionary)、VBScript の正規表現(RegExp)、ADO の Stream の型定義です。どれも VBA プロジェクトの参照設定には入っていないので、生成する VBA では遅延バインディングになります(変数は Object、作成は CreateObject(…)、列挙値は数値)。RAS では new Scripting.FileSystemObject() / new Scripting.Dictionary() / new VBScript.RegExp() で作ります。
- 正規表現はリテラル
/^\d+$/iでも書けます(VBScript.RegExpになります)。 Map<K, V>はScripting.Dictionary相当です。- ファイルの読み書きには、RAS標準ライブラリの fs が使えます(文字コードの指定も)。
- Excel なしの実行でも、
Scripting.FileSystemObject・Scripting.Dictionary・VBScript.RegExpは使えます。
リファレンス
列挙型 Scripting.IOMode
openTextFile / openAsTextStream でファイルを開く目的。
列挙型 Scripting.Tristate
テキスト ファイルの文字コード。tristateFalse は ANSI(日本語 Windows では Shift_JIS)、tristateTrue は Unicode(UTF-16)。
列挙型 Scripting.SpecialFolderConst
getSpecialFolder で取得するフォルダー。
インターフェイス Scripting.FileSystemObject
ファイル・フォルダーを操作する。new Scripting.FileSystemObject() で作成する。
- #
buildPath(path: string, name: string): string
パスの末尾に名前をつなぐ(区切り文字は必要なときだけ入る)。
VBA:
BuildPath- #
copyFile(source: string, destination: string, overWriteFiles?: boolean): void
ファイルをコピーする。コピー元の最後の部分にはワイルドカード(
*?)を使える。VBA:
CopyFile- #
copyFolder(source: string, destination: string, overWriteFiles?: boolean): void
フォルダーを中身ごとコピーする。
VBA:
CopyFolder- #
createFolder(path: string): Folder
フォルダーを作成する。既にあるとエラー 58。
VBA:
CreateFolder- #
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream
テキスト ファイルを作成して開く。
unicodeがtrueなら UTF-16、既定は ANSI。VBA:
CreateTextFile- #
deleteFile(fileSpec: string, force?: boolean): void
ファイルを削除する。最後の部分にはワイルドカードを使える。1 つも無いとエラー 53。
VBA:
DeleteFile- #
deleteFolder(folderSpec: string, force?: boolean): void
フォルダーを中身ごと削除する。
VBA:
DeleteFolder- #
driveExists(driveSpec: string): boolean
ドライブがあるかどうか。
VBA:
DriveExists- #
fileExists(fileSpec: string): boolean
ファイルがあるかどうか。
VBA:
FileExists- #
folderExists(folderSpec: string): boolean
フォルダーがあるかどうか。
VBA:
FolderExists- #
getAbsolutePathName(path: string): string
絶対パスに直す。
VBA:
GetAbsolutePathName- #
getBaseName(path: string): string
パスの最後の部分から拡張子を除いた名前。
VBA:
GetBaseName- #
getDriveName(path: string): string
パスのドライブ名(
C:)。VBA:
GetDriveName- #
getExtensionName(path: string): string
パスの最後の部分の拡張子(
.は含まない)。VBA:
GetExtensionName- #
getFile(filePath: string): File
ファイルを表す
Fileを返す。無いとエラー 53。VBA:
GetFile- #
getFileName(path: string): string
パスの最後の部分(ファイル名)。
VBA:
GetFileName- #
getFolder(folderPath: string): Folder
フォルダーを表す
Folderを返す。無いとエラー 76。VBA:
GetFolder- #
getParentFolderName(path: string): string
パスの最後の部分を除いた、親フォルダーのパス。
VBA:
GetParentFolderName- #
getSpecialFolder(specialFolder: SpecialFolderConst): Folder
Windows・システム・一時ファイル用のフォルダーを返す。
VBA:
GetSpecialFolder- #
getTempName(): string
一時ファイル用の、重ならない名前(
rad1A2B3.tmp)を作る。ファイルは作らない。VBA:
GetTempName- #
moveFile(source: string, destination: string): void
ファイルを移動する(名前の変更にも使う)。
VBA:
MoveFile- #
moveFolder(source: string, destination: string): void
フォルダーを移動する(名前の変更にも使う)。
VBA:
MoveFolder- #
openTextFile(fileName: string, ioMode?: IOMode, create?: boolean, format?: Tristate): TextStream
テキスト ファイルを開く。
createがtrueなら、無いときに作成する。VBA:
OpenTextFile- #
readonly drives: object
ドライブの一覧。
VBA:
Drives- #
getDrive(driveSpec: string): object
ドライブを表すオブジェクトを返す。
VBA:
GetDrive
インターフェイス Scripting.File
ファイル。FileSystemObject.getFile やフォルダーの files で取得する。
- #
name: string
ファイル名。代入すると名前を変更する。
VBA:
Name- #
readonly path: string
フル パス。
VBA:
Path- #
readonly shortName: string
短い形式(8.3)のファイル名。
VBA:
ShortName- #
readonly shortPath: string
短い形式(8.3)のパス。
VBA:
ShortPath- #
readonly parentFolder: Folder
親フォルダー。
VBA:
ParentFolder- #
readonly drive: object
ドライブ。
VBA:
Drive- #
readonly size: any
サイズ(バイト)。
VBA:
Size- #
readonly type: string
ファイルの種類の説明(
テキスト ドキュメントなど)。VBA:
Type- #
attributes: int
属性(
vbReadOnly・vbHiddenなどの組み合わせ)。VBA:
Attributes- #
readonly dateCreated: date
作成日時。
VBA:
DateCreated- #
readonly dateLastAccessed: date
最終アクセス日時。
VBA:
DateLastAccessed- #
readonly dateLastModified: date
最終更新日時。
VBA:
DateLastModified- #
copy(destination: string, overWriteFiles?: boolean): void
コピーする。
VBA:
Copy- #
move(destination: string): void
移動する。
VBA:
Move- #
delete(force?: boolean): void
削除する。
VBA:
Delete- #
openAsTextStream(ioMode?: IOMode, format?: Tristate): TextStream
テキスト ファイルとして開く。
VBA:
OpenAsTextStream
インターフェイス Scripting.Files
フォルダーの中のファイルの集まり。for...of で列挙でき、ファイル名で取り出せる。
インターフェイス Scripting.Folder
フォルダー。FileSystemObject.getFolder などで取得する。
- #
name: string
フォルダー名。代入すると名前を変更する。
VBA:
Name- #
readonly path: string
フル パス。
VBA:
Path- #
readonly shortName: string
短い形式(8.3)のフォルダー名。
VBA:
ShortName- #
readonly shortPath: string
短い形式(8.3)のパス。
VBA:
ShortPath- #
readonly parentFolder: Folder
親フォルダー。ルート フォルダーでは
null。VBA:
ParentFolder- #
readonly drive: object
ドライブ。
VBA:
Drive- #
readonly isRootFolder: boolean
ルート フォルダーかどうか。
VBA:
IsRootFolder- #
readonly size: any
中のファイルとサブフォルダーをすべて合わせたサイズ(バイト)。
VBA:
Size- #
readonly type: string
フォルダーの種類の説明。
VBA:
Type- #
attributes: int
属性(
vbDirectoryなどの組み合わせ)。VBA:
Attributes- #
readonly dateCreated: date
作成日時。
VBA:
DateCreated- #
readonly dateLastAccessed: date
最終アクセス日時。
VBA:
DateLastAccessed- #
readonly dateLastModified: date
最終更新日時。
VBA:
DateLastModified- #
readonly files: Files
中のファイル。
VBA:
Files- #
readonly subFolders: Folders
サブフォルダー。
VBA:
SubFolders- #
copy(destination: string, overWriteFiles?: boolean): void
中身ごとコピーする。
VBA:
Copy- #
move(destination: string): void
移動する。
VBA:
Move- #
delete(force?: boolean): void
中身ごと削除する。
VBA:
Delete- #
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream
このフォルダーにテキスト ファイルを作成して開く。
VBA:
CreateTextFile
インターフェイス Scripting.Folders
フォルダーの中のサブフォルダーの集まり。for...of で列挙でき、フォルダー名で取り出せる。
インターフェイス Scripting.TextStream
開いているテキスト ファイル。順に読むか、順に書く。
- #
readonly atEndOfLine: boolean
行の終わり(改行の直前)にいるかどうか。
VBA:
AtEndOfLine- #
readonly atEndOfStream: boolean
ファイルの終わりにいるかどうか。
VBA:
AtEndOfStream- #
readonly column: int
現在の桁(1 始まり)。
VBA:
Column- #
readonly line: int
現在の行(1 始まり)。
VBA:
Line- #
close(): void
閉じる。書き込んだ内容はここでファイルに確定する。
VBA:
Close- #
read(characters: int): string
指定した文字数を読む。
VBA:
Read- #
readAll(): string
残りをすべて読む。
VBA:
ReadAll- #
readLine(): string
1 行読む(改行は含まない)。
VBA:
ReadLine- #
skip(characters: int): void
指定した文字数を読み飛ばす。
VBA:
Skip- #
skipLine(): void
1 行読み飛ばす。
VBA:
SkipLine- #
write(text: string): void
文字列を書く(改行は付かない)。
VBA:
Write- #
writeBlankLines(lines: int): void
空の行を書く。
VBA:
WriteBlankLines- #
writeLine(text?: string): void
文字列と改行(CRLF)を書く。
VBA:
WriteLine
インターフェイス Scripting.Dictionary
キーと値の組を保持する辞書。RAS では通常 Map<K, V> を使う(同じ Scripting.Dictionary に変換される)。この型は、CreateObject("Scripting.Dictionary") をそのまま使う既存のコードのためにある。for...of はキーを列挙する。
- #
(key: any): any
キーの値を返す(既定メンバー)。無いキーを読むと、空の値でそのキーが追加される。
d[key] = valueで設定する。引数のあるプロパティです(
x(…) = 値と代入できます)。- #
item(key: any): any
キーの値を返す。
引数のあるプロパティです(
x(…) = 値と代入できます)。VBA:
Item- #
readonly count: int
組の数。
VBA:
Count- #
compareMode: VBA.VbCompareMethod
キーの比べ方(
vbBinaryCompare/vbTextCompare)。空のときだけ変更できる。VBA:
CompareMode- #
add(key: any, item: any): void
組を追加する。キーが既にあるとエラー 457。
VBA:
Add- #
exists(key: any): boolean
キーがあるかどうか。
VBA:
Exists- #
items(): any[]
値の配列(0 始まり)を返す。
VBA:
Items- #
keys(): any[]
キーの配列(0 始まり)を返す。
VBA:
Keys- #
remove(key: any): void
組を削除する。キーが無いとエラー 32811。
VBA:
Remove- #
removeAll(): void
すべての組を削除する。
VBA:
RemoveAll
インターフェイス VBScript.RegExp
正規表現。new VBScript.RegExp() で作成する。
- #
pattern: string
正規表現のパターン。
VBA:
Pattern- #
global: boolean
文字列全体から、一致するものをすべて探すかどうか(既定は最初の 1 つ)。
VBA:
Global- #
ignoreCase: boolean
大文字と小文字を区別しないかどうか。
VBA:
IgnoreCase- #
multiline: boolean
^と$を各行の先頭と末尾にも一致させるかどうか。VBA:
Multiline- #
test(sourceString: string): boolean
パターンに一致する部分があるかどうか。
VBA:
Test- #
execute(sourceString: string): MatchCollection
一致した部分の集まりを返す。
VBA:
Execute- #
replace(sourceString: string, replaceVar: any): string
一致した部分を置き換えた文字列を返す。置き換える文字列では
$1・$&などを使える。VBA:
Replace
インターフェイス VBScript.MatchCollection
RegExp.execute が返す、一致した部分の集まり(0 始まり)。for...of で列挙できる。
インターフェイス VBScript.Match
パターンに一致した 1 つの部分。
- #
readonly value: string
一致した文字列。
VBA:
Value- #
readonly firstIndex: int
元の文字列の中の位置(0 始まり)。
VBA:
FirstIndex- #
readonly length: int
一致した文字列の長さ。
VBA:
Length- #
readonly subMatches: SubMatches
パターンの
( )に一致した部分。VBA:
SubMatches
インターフェイス VBScript.SubMatches
パターンの ( ) に一致した文字列の集まり(0 始まり)。一致しなかった ( ) は空(Empty)。
列挙型 ADODB.StreamTypeEnum
Stream の中身の種類(type)。
列挙型 ADODB.SaveOptionsEnum
saveToFile で、ファイルがあるときの扱い。
列挙型 ADODB.StreamReadEnum
readText で読む量。
列挙型 ADODB.StreamWriteEnum
writeText で、改行を付けるか。
列挙型 ADODB.LineSeparatorEnum
行の区切り(lineSeparator)。
インターフェイス ADODB.Stream
バイト列・テキストを読み書きするメモリー上のストリーム。new ADODB.Stream() で作成し、open() してから使う。テキストの文字コードは charset("utf-8"、"shift_jis"、"unicode"(UTF-16 LE)、"unicodeFFFE"(UTF-16 BE)、"euc-jp"、"iso-2022-jp" など)。
"utf-8" と "unicode" で書くと、先頭に BOM が付く。
- #
type: StreamTypeEnum
中身の種類(
adTypeBinary/adTypeText)。変えられるのはpositionが 0 のときだけ。VBA:
Type- #
charset: string
テキストの文字コード(既定
"unicode")。変えられるのはpositionが 0 のときだけ。VBA:
Charset- #
position: int
現在の位置(バイト。0 始まり)。
VBA:
Position- #
readonly size: int
大きさ(バイト)。
VBA:
Size- #
readonly eos: boolean
終わりにいるかどうか。
VBA:
EOS- #
lineSeparator: LineSeparatorEnum
readText(adReadLine)/writeText(…, adWriteLine)の行の区切り。VBA:
LineSeparator- #
readonly state: int
開いているか(1)、閉じているか(0)。
VBA:
State- #
open(): void
開く(空のストリームになる)。
VBA:
Open- #
close(): void
閉じる。
VBA:
Close- #
loadFromFile(fileName: string): void
ファイルの内容を読み込む(中身が置き換わり、
positionは 0 になる)。VBA:
LoadFromFile- #
saveToFile(fileName: string, options?: SaveOptionsEnum): void
中身をすべてファイルに書く。
VBA:
SaveToFile- #
readText(numChars?: int): string
テキストを読む(
adTypeTextのとき)。既定は残りすべて。VBA:
ReadText- #
writeText(data: string, options?: StreamWriteEnum): void
テキストを書く(
adTypeTextのとき)。VBA:
WriteText- #
read(numBytes?: int): any
バイト列を読む(
adTypeBinaryのとき。Byteの配列)。既定は残りすべて。VBA:
Read- #
write(buffer: any): void
バイト列(
Byteの配列)を書く(adTypeBinaryのとき)。VBA:
Write- #
copyTo(destStream: Stream, numChars?: int): void
現在の位置から(
numChars文字・バイトだけ。既定は残りすべて)を、別のストリームの現在の位置へ写す。VBA:
CopyTo- #
setEOS(): void
現在の位置を終わりにする(後ろを切り捨てる)。
VBA:
SetEOS- #
skipLine(): void
1 行読み飛ばす。
VBA:
SkipLine- #
flush(): void
バッファーの内容を確定する。
VBA:
Flush