Type definitions (Excel, VBA)
Scripting, VBScript and ADODB
These are the type definitions for the Microsoft Scripting Runtime (FileSystemObject, Dictionary), VBScript regular expressions (RegExp) and ADO's Stream. None of them is in the VBA project's references, so the generated VBA uses late binding (variables are Object, they are created with CreateObject(…), and enum values are numbers). In RAS you create them with new Scripting.FileSystemObject() / new Scripting.Dictionary() / new VBScript.RegExp().
- Regular expressions can also be written as literals such as
/^\d+$/i(they becomeVBScript.RegExp). Map<K, V>corresponds toScripting.Dictionary.- For reading and writing files, fs of the RAS standard library is available (including specifying the encoding).
Scripting.FileSystemObject,Scripting.DictionaryandVBScript.RegExpalso work when running without Excel.
Reference
Enum Scripting.IOMode
What a file is opened for with openTextFile / openAsTextStream.
Enum Scripting.Tristate
The encoding of a text file. tristateFalse is ANSI (Shift_JIS on Japanese Windows), tristateTrue is Unicode (UTF-16).
Enum Scripting.SpecialFolderConst
The folder to get with getSpecialFolder.
Interface Scripting.FileSystemObject
Works with files and folders. Create one with new Scripting.FileSystemObject().
- #
buildPath(path: string, name: string): string
Appends a name to the end of a path (a separator is inserted only when needed).
VBA:
BuildPath- #
copyFile(source: string, destination: string, overWriteFiles?: boolean): void
Copies files. The last part of the source can contain wildcards (
*?).VBA:
CopyFile- #
copyFolder(source: string, destination: string, overWriteFiles?: boolean): void
Copies a folder with its contents.
VBA:
CopyFolder- #
createFolder(path: string): Folder
Creates a folder. Error 58 if it already exists.
VBA:
CreateFolder- #
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream
Creates and opens a text file. UTF-16 when
unicodeistrue; ANSI by default.VBA:
CreateTextFile- #
deleteFile(fileSpec: string, force?: boolean): void
Deletes files. The last part can contain wildcards. Error 53 if none exist.
VBA:
DeleteFile- #
deleteFolder(folderSpec: string, force?: boolean): void
Deletes a folder with its contents.
VBA:
DeleteFolder- #
driveExists(driveSpec: string): boolean
Whether the drive exists.
VBA:
DriveExists- #
fileExists(fileSpec: string): boolean
Whether the file exists.
VBA:
FileExists- #
folderExists(folderSpec: string): boolean
Whether the folder exists.
VBA:
FolderExists- #
getAbsolutePathName(path: string): string
Converts to an absolute path.
VBA:
GetAbsolutePathName- #
getBaseName(path: string): string
The last part of the path without its extension.
VBA:
GetBaseName- #
getDriveName(path: string): string
The drive name of the path (
C:).VBA:
GetDriveName- #
getExtensionName(path: string): string
The extension of the last part of the path (without the
.).VBA:
GetExtensionName- #
getFile(filePath: string): File
Returns a
Filefor the file. Error 53 if it does not exist.VBA:
GetFile- #
getFileName(path: string): string
The last part of the path (the file name).
VBA:
GetFileName- #
getFolder(folderPath: string): Folder
Returns a
Folderfor the folder. Error 76 if it does not exist.VBA:
GetFolder- #
getParentFolderName(path: string): string
The path of the parent folder (the path without its last part).
VBA:
GetParentFolderName- #
getSpecialFolder(specialFolder: SpecialFolderConst): Folder
Returns the Windows, system or temporary folder.
VBA:
GetSpecialFolder- #
getTempName(): string
Makes a unique name for a temporary file (
rad1A2B3.tmp). No file is created.VBA:
GetTempName- #
moveFile(source: string, destination: string): void
Moves files (also used to rename).
VBA:
MoveFile- #
moveFolder(source: string, destination: string): void
Moves a folder (also used to rename).
VBA:
MoveFolder- #
openTextFile(fileName: string, ioMode?: IOMode, create?: boolean, format?: Tristate): TextStream
Opens a text file. When
createistrue, it is created if it does not exist.VBA:
OpenTextFile- #
readonly drives: object
The list of drives.
VBA:
Drives- #
getDrive(driveSpec: string): object
Returns an object for the drive.
VBA:
GetDrive
Interface Scripting.File
A file. Get one with FileSystemObject.getFile or a folder's files.
- #
name: string
The file name. Assigning to it renames the file.
VBA:
Name- #
readonly path: string
The full path.
VBA:
Path- #
readonly shortName: string
The short (8.3) file name.
VBA:
ShortName- #
readonly shortPath: string
The short (8.3) path.
VBA:
ShortPath- #
readonly parentFolder: Folder
The parent folder.
VBA:
ParentFolder- #
readonly drive: object
The drive.
VBA:
Drive- #
readonly size: any
The size (bytes).
VBA:
Size- #
readonly type: string
A description of the file type (
Text Documentand so on).VBA:
Type- #
attributes: int
The attributes (a combination of
vbReadOnly,vbHiddenand so on).VBA:
Attributes- #
readonly dateCreated: date
When it was created.
VBA:
DateCreated- #
readonly dateLastAccessed: date
When it was last accessed.
VBA:
DateLastAccessed- #
readonly dateLastModified: date
When it was last modified.
VBA:
DateLastModified- #
copy(destination: string, overWriteFiles?: boolean): void
Copies it.
VBA:
Copy- #
move(destination: string): void
Moves it.
VBA:
Move- #
delete(force?: boolean): void
Deletes it.
VBA:
Delete- #
openAsTextStream(ioMode?: IOMode, format?: Tristate): TextStream
Opens it as a text file.
VBA:
OpenAsTextStream
Interface Scripting.Files
The files in a folder. Can be enumerated with for...of and indexed by file name.
Interface Scripting.Folder
A folder. Get one with FileSystemObject.getFolder and so on.
- #
name: string
The folder name. Assigning to it renames the folder.
VBA:
Name- #
readonly path: string
The full path.
VBA:
Path- #
readonly shortName: string
The short (8.3) folder name.
VBA:
ShortName- #
readonly shortPath: string
The short (8.3) path.
VBA:
ShortPath- #
readonly parentFolder: Folder
The parent folder.
nullfor a root folder.VBA:
ParentFolder- #
readonly drive: object
The drive.
VBA:
Drive- #
readonly isRootFolder: boolean
Whether it is a root folder.
VBA:
IsRootFolder- #
readonly size: any
The total size of all the files and subfolders inside (bytes).
VBA:
Size- #
readonly type: string
A description of the folder type.
VBA:
Type- #
attributes: int
The attributes (a combination of
vbDirectoryand so on).VBA:
Attributes- #
readonly dateCreated: date
When it was created.
VBA:
DateCreated- #
readonly dateLastAccessed: date
When it was last accessed.
VBA:
DateLastAccessed- #
readonly dateLastModified: date
When it was last modified.
VBA:
DateLastModified- #
readonly files: Files
The files inside.
VBA:
Files- #
readonly subFolders: Folders
The subfolders.
VBA:
SubFolders- #
copy(destination: string, overWriteFiles?: boolean): void
Copies it with its contents.
VBA:
Copy- #
move(destination: string): void
Moves it.
VBA:
Move- #
delete(force?: boolean): void
Deletes it with its contents.
VBA:
Delete- #
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream
Creates and opens a text file in this folder.
VBA:
CreateTextFile
Interface Scripting.Folders
The subfolders of a folder. Can be enumerated with for...of and indexed by folder name.
Interface Scripting.TextStream
An open text file, read or written sequentially.
- #
readonly atEndOfLine: boolean
Whether the position is at the end of a line (just before a line break).
VBA:
AtEndOfLine- #
readonly atEndOfStream: boolean
Whether the position is at the end of the file.
VBA:
AtEndOfStream- #
readonly column: int
The current column (1-based).
VBA:
Column- #
readonly line: int
The current line (1-based).
VBA:
Line- #
close(): void
Closes it. What was written is committed to the file here.
VBA:
Close- #
read(characters: int): string
Reads the given number of characters.
VBA:
Read- #
readAll(): string
Reads all the rest.
VBA:
ReadAll- #
readLine(): string
Reads one line (without the line break).
VBA:
ReadLine- #
skip(characters: int): void
Skips the given number of characters.
VBA:
Skip- #
skipLine(): void
Skips one line.
VBA:
SkipLine- #
write(text: string): void
Writes a string (no line break is added).
VBA:
Write- #
writeBlankLines(lines: int): void
Writes empty lines.
VBA:
WriteBlankLines- #
writeLine(text?: string): void
Writes a string and a line break (CRLF).
VBA:
WriteLine
Interface Scripting.Dictionary
A dictionary holding key-value pairs. In RAS you normally use Map<K, V> (converted to the same Scripting.Dictionary).
This type exists for existing code that uses CreateObject("Scripting.Dictionary") directly. for...of enumerates the keys.
- #
(key: any): any
Returns the value for the key (default member). Reading a missing key adds it with an empty value. Set with
d[key] = value.A property with arguments (it can be assigned to:
x(…) = value).- #
item(key: any): any
Returns the value for the key.
A property with arguments (it can be assigned to:
x(…) = value).VBA:
Item- #
readonly count: int
The number of pairs.
VBA:
Count- #
compareMode: VBA.VbCompareMethod
How keys are compared (
vbBinaryCompare/vbTextCompare). Can only be changed while empty.VBA:
CompareMode- #
add(key: any, item: any): void
Adds a pair. Error 457 if the key already exists.
VBA:
Add- #
exists(key: any): boolean
Whether the key exists.
VBA:
Exists- #
items(): any[]
Returns an array of the values (0-based).
VBA:
Items- #
keys(): any[]
Returns an array of the keys (0-based).
VBA:
Keys- #
remove(key: any): void
Removes a pair. Error 32811 if the key does not exist.
VBA:
Remove- #
removeAll(): void
Removes every pair.
VBA:
RemoveAll
Interface VBScript.RegExp
A regular expression. Create one with new VBScript.RegExp().
- #
pattern: string
The pattern of the regular expression.
VBA:
Pattern- #
global: boolean
Whether to find every match in the whole string (by default only the first).
VBA:
Global- #
ignoreCase: boolean
Whether case is ignored.
VBA:
IgnoreCase- #
multiline: boolean
Whether
^and$also match at the start and end of each line.VBA:
Multiline- #
test(sourceString: string): boolean
Whether some part matches the pattern.
VBA:
Test- #
execute(sourceString: string): MatchCollection
Returns the matches.
VBA:
Execute- #
replace(sourceString: string, replaceVar: any): string
Returns the string with the matches replaced. The replacement can use
$1,$&and so on.VBA:
Replace
Interface VBScript.MatchCollection
The matches returned by RegExp.execute (0-based). Can be enumerated with for...of.
Interface VBScript.Match
One part that matched the pattern.
- #
readonly value: string
The matched string.
VBA:
Value- #
readonly firstIndex: int
The position in the original string (0-based).
VBA:
FirstIndex- #
readonly length: int
The length of the matched string.
VBA:
Length- #
readonly subMatches: SubMatches
The parts that matched the
( )of the pattern.VBA:
SubMatches
Interface VBScript.SubMatches
The strings that matched the ( ) of the pattern (0-based). A ( ) that did not match is empty (Empty).
Enum ADODB.StreamTypeEnum
The kind of content of a Stream (type).
Enum ADODB.SaveOptionsEnum
What saveToFile does when the file exists.
Enum ADODB.StreamReadEnum
How much readText reads.
Enum ADODB.StreamWriteEnum
Whether writeText adds a line break.
Enum ADODB.LineSeparatorEnum
The line separator (lineSeparator).
Interface ADODB.Stream
An in-memory stream for reading and writing bytes and text. Create one with new ADODB.Stream() and open() it before use.
The encoding of text is charset ("utf-8", "shift_jis", "unicode" (UTF-16 LE), "unicodeFFFE" (UTF-16 BE), "euc-jp", "iso-2022-jp" and so on).
Writing with "utf-8" and "unicode" puts a BOM at the start.
- #
type: StreamTypeEnum
The kind of content (
adTypeBinary/adTypeText). Can only be changed whenpositionis 0.VBA:
Type- #
charset: string
The encoding of text (default
"unicode"). Can only be changed whenpositionis 0.VBA:
Charset- #
position: int
The current position (bytes, 0-based).
VBA:
Position- #
readonly size: int
The size (bytes).
VBA:
Size- #
readonly eos: boolean
Whether the position is at the end.
VBA:
EOS- #
lineSeparator: LineSeparatorEnum
The line separator of
readText(adReadLine)/writeText(…, adWriteLine).VBA:
LineSeparator- #
readonly state: int
Whether it is open (1) or closed (0).
VBA:
State- #
open(): void
Opens it (as an empty stream).
VBA:
Open- #
close(): void
Closes it.
VBA:
Close- #
loadFromFile(fileName: string): void
Loads the contents of a file (replacing the content;
positionbecomes 0).VBA:
LoadFromFile- #
saveToFile(fileName: string, options?: SaveOptionsEnum): void
Writes all the content to a file.
VBA:
SaveToFile- #
readText(numChars?: int): string
Reads text (with
adTypeText). All the rest by default.VBA:
ReadText- #
writeText(data: string, options?: StreamWriteEnum): void
Writes text (with
adTypeText).VBA:
WriteText- #
read(numBytes?: int): any
Reads bytes (with
adTypeBinary; an array ofByte). All the rest by default.VBA:
Read- #
write(buffer: any): void
Writes bytes (an array of
Byte) (withadTypeBinary).VBA:
Write- #
copyTo(destStream: Stream, numChars?: int): void
Copies from the current position (only
numCharscharacters or bytes; all the rest by default) to the current position of another stream.VBA:
CopyTo- #
setEOS(): void
Makes the current position the end (truncating what follows).
VBA:
SetEOS- #
skipLine(): void
Skips one line.
VBA:
SkipLine- #
flush(): void
Commits the content of the buffer.
VBA:
Flush