Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

OfficeVbaProject

OfficeIMO

Namespace
OfficeIMO
Assembly
OfficeIMO.Core
Source revision
1f76172c94d1 with working tree changes
Modifiers
sealed

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

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 required
source string required
baseClassId System.Guid required
public 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 required
source string required
kind OfficeIMO.OfficeVbaModuleKind = Standard optional
public 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 required
typeLibraryId System.Guid required
majorVersion int = 1 optional
minorVersion int = 0 optional
path string = "" optional

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" optional
codePage int = 1252 optional
public void DeleteModule(string name) #

Deletes a standard or class module. Host-owned and designer modules remain under their owning document.

Parameters

name string required
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 required
public OfficeVbaModule GetModule(string name) #

Gets a module by its case-insensitive logical name.

Parameters

name string required
public 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 required
maximumSourceBytes int = 67108864 optional
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[] required
options OfficeIMO.OfficeVbaReadOptions? = null optional

Exceptions

  • 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 required

Returns

bool
public 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 required
newName string required
public void SetModuleSource(string name, string source) #

Replaces source while preserving module kind, attributes, and the rest of the project.

Parameters

name string required
source string required
public OfficeVbaWriteResult Write(OfficeVbaWriteOptions? options = null) #

Produces a bounded complete project; unchanged projects retain their original bytes and signatures.

Parameters

options OfficeIMO.OfficeVbaWriteOptions? = null optional

Properties

public string Name { get; } #

Gets the project's persisted name.

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.