OfficeVbaProject
OfficeIMO
Reads and edits a host-neutral VBA compound project without executing or compiling its source.
Inheritance
- object
- OfficeVbaProject
Usage
Explore 2 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 2
- Method OfficeVbaProject.Create
- Method OfficeVbaProject.Load
Methods
public OfficeVbaModule AddDocumentModule(string name, string source, Guid baseClassId) #Adds a host-owned module whose VB_Base class identity is supplied by the document adapter.
Parameters
- name string
- source string
- baseClassId System.Guid
Returns
OfficeVbaModulepublic OfficeVbaModule AddModule(string name, string source, OfficeVbaModuleKind kind = Standard) #Adds a standard or ordinary class module; host document and designer identities require their own owners.
Parameters
- name string
- source string
- kind OfficeIMO.OfficeVbaModuleKind = Standard
Returns
OfficeVbaModulepublic OfficeVbaReference AddRegisteredReference(string name, Guid typeLibraryId, int majorVersion = 1, int minorVersion = 0, string path = "") #Adds a registered type-library reference without installing or executing that library.
Parameters
- name string
- typeLibraryId System.Guid
- majorVersion int = 1
- minorVersion int = 0
- path string = ""
Returns
OfficeVbaReference The added reference, or the existing reference with the same type-library identity.public static OfficeVbaProject Create(string name = "VBAProject", int codePage = 1252) #Creates a template-free VBA project with a native directory and source-only compilation state.
Parameters
- name string = "VBAProject"
- codePage int = 1252
Returns
OfficeVbaProjectpublic void DeleteModule(string name) #Deletes a standard or class module. Host-owned and designer modules remain under their owning document.
Parameters
- name string
public void ExportSources(string directory) #Exports UTF-8 source files and a typed XML manifest to a new directory for version control.
Parameters
- directory string
public OfficeVbaModule GetModule(string name) #Gets a module by its case-insensitive logical name.
Parameters
- name string
Returns
OfficeVbaModulepublic void ImportSources(string directory, int maximumSourceBytes = 67108864) #Imports the source files named in an exported manifest, with validation before any project mutation.
Parameters
- directory string
- maximumSourceBytes int = 67108864
public static OfficeVbaProject Load(byte[] projectBytes, OfficeVbaReadOptions? options = null) #Loads a detached project with aggregate input, compound-stream, and expanded-source limits.
Parameters
- projectBytes byte[]
- options OfficeIMO.OfficeVbaReadOptions? = null
Returns
OfficeVbaProjectExceptions
InvalidDataException– The project is malformed or its persisted text encoding is invalid or unavailable.
public bool RemoveReference(string name) #Removes one explicit reference without rewriting source that uses its types.
Parameters
- name string
Returns
boolpublic void RenameModule(string name, string newName) #Renames a standard or class module and its project/stream identities; source code references are not rewritten.
Parameters
- name string
- newName string
public void SetModuleSource(string name, string source) #Replaces source while preserving module kind, attributes, and the rest of the project.
Parameters
- name string
- source string
public OfficeVbaWriteResult Write(OfficeVbaWriteOptions? options = null) #Produces a bounded complete project; unchanged projects retain their original bytes and signatures.
Parameters
- options OfficeIMO.OfficeVbaWriteOptions? = null
Returns
OfficeVbaWriteResultInherited Methods
Properties
public int CodePage { get; } #Gets the Windows code page used by source and ANSI project records.
public IReadOnlyList<OfficeVbaModule> Modules { get; } #Gets the source modules in directory order.
public IReadOnlyList<OfficeVbaReference> References { get; } #Gets the project's explicit library references.
public bool IsProtected { get; private set; } #Gets whether the project declares password or access protection; protected projects remain readable.
public bool HasChanges { get; } #Gets whether editing operations differ from the loaded source project.