RAS プレイグラウンド English GitHub

型定義(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() で作ります。

リファレンス

列挙型 Scripting.IOMode

openTextFile / openAsTextStream でファイルを開く目的。

Microsoft のリファレンス

#
forReading = 1

読み取り。

#
forWriting = 2

書き込み(内容は上書きされる)。

#
forAppending = 8

末尾への追記。

scripting.d.ras

列挙型 Scripting.Tristate

テキスト ファイルの文字コード。tristateFalse は ANSI(日本語 Windows では Shift_JIS)、tristateTrue は Unicode(UTF-16)。

Microsoft のリファレンス

#
tristateTrue = -1
#
tristateFalse = 0
#
tristateUseDefault = -2

システムの既定(ANSI)。

scripting.d.ras

列挙型 Scripting.SpecialFolderConst

getSpecialFolder で取得するフォルダー。

Microsoft のリファレンス

#
windowsFolder = 0
#
systemFolder = 1
#
temporaryFolder = 2

一時ファイル用のフォルダー(TMP)。

scripting.d.ras

インターフェイス Scripting.FileSystemObject

ファイル・フォルダーを操作する。new Scripting.FileSystemObject() で作成する。

Microsoft のリファレンス

#
buildPath(path: string, name: string): string

パスの末尾に名前をつなぐ(区切り文字は必要なときだけ入る)。

Microsoft のリファレンス

VBA: BuildPath

#
copyFile(source: string, destination: string, overWriteFiles?: boolean): void

ファイルをコピーする。コピー元の最後の部分にはワイルドカード(* ?)を使える。

Microsoft のリファレンス

VBA: CopyFile

#
copyFolder(source: string, destination: string, overWriteFiles?: boolean): void

フォルダーを中身ごとコピーする。

Microsoft のリファレンス

VBA: CopyFolder

#
createFolder(path: string): Folder

フォルダーを作成する。既にあるとエラー 58。

Microsoft のリファレンス

VBA: CreateFolder

#
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream

テキスト ファイルを作成して開く。unicode が true なら UTF-16、既定は ANSI。

Microsoft のリファレンス

VBA: CreateTextFile

#
deleteFile(fileSpec: string, force?: boolean): void

ファイルを削除する。最後の部分にはワイルドカードを使える。1 つも無いとエラー 53。

Microsoft のリファレンス

VBA: DeleteFile

#
deleteFolder(folderSpec: string, force?: boolean): void

フォルダーを中身ごと削除する。

Microsoft のリファレンス

VBA: DeleteFolder

#
driveExists(driveSpec: string): boolean

ドライブがあるかどうか。

Microsoft のリファレンス

VBA: DriveExists

#
fileExists(fileSpec: string): boolean

ファイルがあるかどうか。

Microsoft のリファレンス

VBA: FileExists

#
folderExists(folderSpec: string): boolean

フォルダーがあるかどうか。

Microsoft のリファレンス

VBA: FolderExists

#
getAbsolutePathName(path: string): string

絶対パスに直す。

Microsoft のリファレンス

VBA: GetAbsolutePathName

#
getBaseName(path: string): string

パスの最後の部分から拡張子を除いた名前。

Microsoft のリファレンス

VBA: GetBaseName

#
getDriveName(path: string): string

パスのドライブ名(C:)。

Microsoft のリファレンス

VBA: GetDriveName

#
getExtensionName(path: string): string

パスの最後の部分の拡張子(. は含まない)。

Microsoft のリファレンス

VBA: GetExtensionName

#
getFile(filePath: string): File

ファイルを表す File を返す。無いとエラー 53。

Microsoft のリファレンス

VBA: GetFile

#
getFileName(path: string): string

パスの最後の部分(ファイル名)。

Microsoft のリファレンス

VBA: GetFileName

#
getFolder(folderPath: string): Folder

フォルダーを表す Folder を返す。無いとエラー 76。

Microsoft のリファレンス

VBA: GetFolder

#
getParentFolderName(path: string): string

パスの最後の部分を除いた、親フォルダーのパス。

Microsoft のリファレンス

VBA: GetParentFolderName

#
getSpecialFolder(specialFolder: SpecialFolderConst): Folder

Windows・システム・一時ファイル用のフォルダーを返す。

Microsoft のリファレンス

VBA: GetSpecialFolder

#
getTempName(): string

一時ファイル用の、重ならない名前(rad1A2B3.tmp)を作る。ファイルは作らない。

Microsoft のリファレンス

VBA: GetTempName

#
moveFile(source: string, destination: string): void

ファイルを移動する(名前の変更にも使う)。

Microsoft のリファレンス

VBA: MoveFile

#
moveFolder(source: string, destination: string): void

フォルダーを移動する(名前の変更にも使う)。

Microsoft のリファレンス

VBA: MoveFolder

#
openTextFile(fileName: string, ioMode?: IOMode, create?: boolean, format?: Tristate): TextStream

テキスト ファイルを開く。create が true なら、無いときに作成する。

Microsoft のリファレンス

VBA: OpenTextFile

#
readonly drives: object

ドライブの一覧。

Microsoft のリファレンス

VBA: Drives

#
getDrive(driveSpec: string): object

ドライブを表すオブジェクトを返す。

Microsoft のリファレンス

VBA: GetDrive

scripting.d.ras

インターフェイス Scripting.File

ファイル。FileSystemObject.getFile やフォルダーの files で取得する。

Microsoft のリファレンス

#
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

コピーする。

Microsoft のリファレンス

VBA: Copy

#
move(destination: string): void

移動する。

Microsoft のリファレンス

VBA: Move

#
delete(force?: boolean): void

削除する。

Microsoft のリファレンス

VBA: Delete

#
openAsTextStream(ioMode?: IOMode, format?: Tristate): TextStream

テキスト ファイルとして開く。

Microsoft のリファレンス

VBA: OpenAsTextStream

scripting.d.ras

インターフェイス Scripting.Files

フォルダーの中のファイルの集まり。for...of で列挙でき、ファイル名で取り出せる。

Microsoft のリファレンス

#
(key: any): File

ファイル名で取り出す(既定メンバー)。

#
item(key: any): File

ファイル名で取り出す。

VBA: Item

#
readonly count: int

ファイルの数。

VBA: Count

scripting.d.ras

インターフェイス Scripting.Folder

フォルダー。FileSystemObject.getFolder などで取得する。

Microsoft のリファレンス

#
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

中身ごとコピーする。

Microsoft のリファレンス

VBA: Copy

#
move(destination: string): void

移動する。

Microsoft のリファレンス

VBA: Move

#
delete(force?: boolean): void

中身ごと削除する。

Microsoft のリファレンス

VBA: Delete

#
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream

このフォルダーにテキスト ファイルを作成して開く。

Microsoft のリファレンス

VBA: CreateTextFile

scripting.d.ras

インターフェイス Scripting.Folders

フォルダーの中のサブフォルダーの集まり。for...of で列挙でき、フォルダー名で取り出せる。

Microsoft のリファレンス

#
(key: any): Folder

フォルダー名で取り出す(既定メンバー)。

#
item(key: any): Folder

フォルダー名で取り出す。

VBA: Item

#
readonly count: int

サブフォルダーの数。

VBA: Count

#
add(name: string): Folder

サブフォルダーを作成する。

Microsoft のリファレンス

VBA: Add

scripting.d.ras

インターフェイス Scripting.TextStream

開いているテキスト ファイル。順に読むか、順に書く。

Microsoft のリファレンス

#
readonly atEndOfLine: boolean

行の終わり(改行の直前)にいるかどうか。

VBA: AtEndOfLine

#
readonly atEndOfStream: boolean

ファイルの終わりにいるかどうか。

VBA: AtEndOfStream

#
readonly column: int

現在の桁(1 始まり)。

VBA: Column

#
readonly line: int

現在の行(1 始まり)。

VBA: Line

#
close(): void

閉じる。書き込んだ内容はここでファイルに確定する。

Microsoft のリファレンス

VBA: Close

#
read(characters: int): string

指定した文字数を読む。

Microsoft のリファレンス

VBA: Read

#
readAll(): string

残りをすべて読む。

Microsoft のリファレンス

VBA: ReadAll

#
readLine(): string

1 行読む(改行は含まない)。

Microsoft のリファレンス

VBA: ReadLine

#
skip(characters: int): void

指定した文字数を読み飛ばす。

Microsoft のリファレンス

VBA: Skip

#
skipLine(): void

1 行読み飛ばす。

Microsoft のリファレンス

VBA: SkipLine

#
write(text: string): void

文字列を書く(改行は付かない)。

Microsoft のリファレンス

VBA: Write

#
writeBlankLines(lines: int): void

空の行を書く。

Microsoft のリファレンス

VBA: WriteBlankLines

#
writeLine(text?: string): void

文字列と改行(CRLF)を書く。

Microsoft のリファレンス

VBA: WriteLine

scripting.d.ras

インターフェイス Scripting.Dictionary

キーと値の組を保持する辞書。RAS では通常 Map<K, V> を使う(同じ Scripting.Dictionary に変換される)。この型は、CreateObject("Scripting.Dictionary") をそのまま使う既存のコードのためにある。for...of はキーを列挙する。

Microsoft のリファレンス

#
(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。

Microsoft のリファレンス

VBA: Add

#
exists(key: any): boolean

キーがあるかどうか。

Microsoft のリファレンス

VBA: Exists

#
items(): any[]

値の配列(0 始まり)を返す。

Microsoft のリファレンス

VBA: Items

#
keys(): any[]

キーの配列(0 始まり)を返す。

Microsoft のリファレンス

VBA: Keys

#
remove(key: any): void

組を削除する。キーが無いとエラー 32811。

Microsoft のリファレンス

VBA: Remove

#
removeAll(): void

すべての組を削除する。

Microsoft のリファレンス

VBA: RemoveAll

scripting.d.ras

インターフェイス VBScript.RegExp

正規表現。new VBScript.RegExp() で作成する。

Microsoft のリファレンス

#
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

scripting.d.ras

インターフェイス VBScript.MatchCollection

RegExp.execute が返す、一致した部分の集まり(0 始まり)。for...of で列挙できる。

#
(index: int): Match

番号(0 始まり)で取り出す(既定メンバー)。

#
item(index: int): Match

番号(0 始まり)で取り出す。

VBA: Item

#
readonly count: int

一致した部分の数。

VBA: Count

scripting.d.ras

インターフェイス VBScript.Match

パターンに一致した 1 つの部分。

#
readonly value: string

一致した文字列。

VBA: Value

#
readonly firstIndex: int

元の文字列の中の位置(0 始まり)。

VBA: FirstIndex

#
readonly length: int

一致した文字列の長さ。

VBA: Length

#
readonly subMatches: SubMatches

パターンの ( ) に一致した部分。

VBA: SubMatches

scripting.d.ras

インターフェイス VBScript.SubMatches

パターンの ( ) に一致した文字列の集まり(0 始まり)。一致しなかった ( ) は空(Empty)。

#
(index: int): any

番号(0 始まり)で取り出す(既定メンバー)。

#
item(index: int): any

番号(0 始まり)で取り出す。

VBA: Item

#
readonly count: int

( ) の数。

VBA: Count

scripting.d.ras

列挙型 ADODB.StreamTypeEnum

Stream の中身の種類(type)。

Microsoft のリファレンス

#
adTypeBinary = 1

バイト列。

#
adTypeText = 2

テキスト(charset の文字コード)。

scripting.d.ras

列挙型 ADODB.SaveOptionsEnum

saveToFile で、ファイルがあるときの扱い。

Microsoft のリファレンス

#
adSaveCreateNotExist = 1

ファイルがなければ作る(あればエラー)。

#
adSaveCreateOverWrite = 2

上書きする。

scripting.d.ras

列挙型 ADODB.StreamReadEnum

readText で読む量。

Microsoft のリファレンス

#
adReadAll = -1

残りをすべて。

#
adReadLine = -2

1 行(lineSeparator まで)。

scripting.d.ras

列挙型 ADODB.StreamWriteEnum

writeText で、改行を付けるか。

Microsoft のリファレンス

#
adWriteChar = 0

文字列だけ。

#
adWriteLine = 1

文字列と改行(lineSeparator)。

scripting.d.ras

列挙型 ADODB.LineSeparatorEnum

行の区切り(lineSeparator)。

Microsoft のリファレンス

#
adCRLF = -1

CR LF(既定)。

#
adLF = 10

LF。

#
adCR = 13

CR。

scripting.d.ras

インターフェイス 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 が付く。

Microsoft のリファレンス

#
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

開く(空のストリームになる)。

Microsoft のリファレンス

VBA: Open

#
close(): void

閉じる。

Microsoft のリファレンス

VBA: Close

#
loadFromFile(fileName: string): void

ファイルの内容を読み込む(中身が置き換わり、position は 0 になる)。

Microsoft のリファレンス

VBA: LoadFromFile

#
saveToFile(fileName: string, options?: SaveOptionsEnum): void

中身をすべてファイルに書く。

Microsoft のリファレンス

VBA: SaveToFile

#
readText(numChars?: int): string

テキストを読む(adTypeText のとき)。既定は残りすべて。

Microsoft のリファレンス

VBA: ReadText

#
writeText(data: string, options?: StreamWriteEnum): void

テキストを書く(adTypeText のとき)。

Microsoft のリファレンス

VBA: WriteText

#
read(numBytes?: int): any

バイト列を読む(adTypeBinary のとき。Byte の配列)。既定は残りすべて。

Microsoft のリファレンス

VBA: Read

#
write(buffer: any): void

バイト列(Byte の配列)を書く(adTypeBinary のとき)。

Microsoft のリファレンス

VBA: Write

#
copyTo(destStream: Stream, numChars?: int): void

現在の位置から(numChars 文字・バイトだけ。既定は残りすべて)を、別のストリームの現在の位置へ写す。

Microsoft のリファレンス

VBA: CopyTo

#
setEOS(): void

現在の位置を終わりにする(後ろを切り捨てる)。

Microsoft のリファレンス

VBA: SetEOS

#
skipLine(): void

1 行読み飛ばす。

Microsoft のリファレンス

VBA: SkipLine

#
flush(): void

バッファーの内容を確定する。

Microsoft のリファレンス

VBA: Flush

scripting.d.ras