Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/

API Reference

Class

OfficeVbaProject

Namespace OfficeIMO
Assembly OfficeIMO.Core
Modifiers sealed

Reads and edits a host-neutral VBA compound project without executing or compiling its source.

Inheritance

  • Object
  • OfficeVbaProject

Usage

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by

Methods

public OfficeVbaModule AddDocumentModule(String name, String source, Guid baseClassId) #
Returns: OfficeVbaModule

Adds a host-owned module whose VB_Base class identity is supplied by the document adapter.

Parameters

name System.String requiredposition: 0
source System.String requiredposition: 1
baseClassId System.Guid requiredposition: 2
public OfficeVbaModule AddModule(String name, String source, OfficeVbaModuleKind kind = Standard) #
Returns: OfficeVbaModule

Adds a standard or ordinary class module; host document and designer identities require their own owners.

Parameters

name System.String requiredposition: 0
source System.String requiredposition: 1
kind OfficeIMO.OfficeVbaModuleKind = Standard optionalposition: 2
public Void AddRegisteredReference(String name, Guid typeLibraryId, Int32 majorVersion = 1, Int32 minorVersion = 0, String path = "") #
Returns: Void

Adds a registered type-library reference without installing or executing that library.

Parameters

name System.String requiredposition: 0
typeLibraryId System.Guid requiredposition: 1
majorVersion System.Int32 = 1 optionalposition: 2
minorVersion System.Int32 = 0 optionalposition: 3
path System.String = "" optionalposition: 4
public static OfficeVbaProject Create(String name = "VBAProject", Int32 codePage = 1252) #
Returns: OfficeVbaProject

Creates a template-free VBA project with a native directory and source-only compilation state.

Parameters

name System.String = "VBAProject" optionalposition: 0
codePage System.Int32 = 1252 optionalposition: 1
public Void DeleteModule(String name) #
Returns: Void

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

Parameters

name System.String requiredposition: 0
public Void ExportSources(String directory) #
Returns: Void

Exports UTF-8 source files and a typed XML manifest to a new directory for version control.

Parameters

directory System.String requiredposition: 0
public OfficeVbaModule GetModule(String name) #
Returns: OfficeVbaModule

Gets a module by its case-insensitive logical name.

Parameters

name System.String requiredposition: 0
public Void ImportSources(String directory, Int32 maximumSourceBytes = 67108864) #
Returns: Void

Imports the source files named in an exported manifest, with validation before any project mutation.

Parameters

directory System.String requiredposition: 0
maximumSourceBytes System.Int32 = 67108864 optionalposition: 1
public static OfficeVbaProject Load(Byte[] projectBytes, OfficeVbaReadOptions options = null) #
Returns: OfficeVbaProject

Loads a detached project with aggregate input, compound-stream, and expanded-source limits.

Parameters

projectBytes System.Byte[] requiredposition: 0
options OfficeIMO.OfficeVbaReadOptions = null optionalposition: 1

Exceptions

  • InvalidDataException – The project is malformed or its persisted text encoding is invalid or unavailable.
public Boolean RemoveReference(String name) #
Returns: Boolean

Removes one explicit reference without rewriting source that uses its types.

Parameters

name System.String requiredposition: 0
public Void RenameModule(String name, String newName) #
Returns: Void

Renames a standard or class module and its project/stream identities; source code references are not rewritten.

Parameters

name System.String requiredposition: 0
newName System.String requiredposition: 1
public Void SetModuleSource(String name, String source) #
Returns: Void

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

Parameters

name System.String requiredposition: 0
source System.String requiredposition: 1
public OfficeVbaWriteResult Write(OfficeVbaWriteOptions options = null) #
Returns: OfficeVbaWriteResult

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

Parameters

options OfficeIMO.OfficeVbaWriteOptions = null optionalposition: 0

Properties

public String Name { get; } #

Gets the project's persisted name.

public Int32 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 Boolean IsProtected { get; private set; } #

Gets whether the project declares password or access protection; protected projects remain readable.

public Boolean HasChanges { get; } #

Gets whether editing operations differ from the loaded source project.