Skip to main content

VbaModule

Struct VbaModule 

Source
pub struct VbaModule {
    pub name: String,
    pub kind: VbaModuleKind,
    pub source: String,
    pub bound_sheet_id: Option<u64>,
    pub prefix_bytes: Vec<u8>,
    pub module_cookie: u16,
    pub cached_compressed_source: Option<Vec<u8>>,
}
Expand description

A single VBA module’s editable content plus the opaque bytes needed to keep Excel happy on export.

Fields§

§name: String

VB_Name – must satisfy validate_vba_module_name.

§kind: VbaModuleKind

What kind of module this is, and so how it binds to the workbook.

§source: String

Plain VBA source text (no compression, no Attribute-line management beyond what the caller writes – callers are expected to include the Attribute VB_Name = "..." line themselves, matching how real Excel-authored module streams are shaped).

§bound_sheet_id: Option<u64>

Required iff kind == Document: the sheet this module’s code belongs to (or None/ignored for ThisWorkbook, which isn’t tied to a specific sheet). Kept as a stable id (not a name) so sheet renames don’t silently orphan the binding – deliberately NOT cascaded the other direction (renaming this module does not rename the sheet, and vice versa; Excel allows the two names to diverge).

§prefix_bytes: Vec<u8>

Opaque bytes forming the pre-TextOffset “p-code prefix” of this module’s stream. Never reparsed or validated by this codebase – proven (via the POC) that its content doesn’t need to correspond to this module’s actual source, only its presence matters, as long as it’s shaped the way real Excel’s module loader expects (a naively zero-filled placeholder of the same length is NOT enough). For an imported module these are the real bytes read back from the original file; for a module created in this codebase they’re vba_synth::synthetic_module_prefix()’s from-scratch, self-consistent zero-procedure cache – see that module’s doc comment.

§module_cookie: u16

The module stream’s MODULECOOKIE record (0x002C) value. MS-OVBA documents this as implementation-specific and ignorable on read, but this codebase used to blindly overwrite every module’s (including untouched, imported ones’) cookie with a hardcoded 0xFFFF on every export – discovered while investigating why every workbook this codebase produces failed has vb project in real Excel, by diffing a re-exported real donor project’s dir stream against the original’s record-by-record and finding this was the one place real data was being discarded and replaced rather than round-tripped verbatim. Preserved here instead so an imported module’s original value survives re-export.

§cached_compressed_source: Option<Vec<u8>>

This module stream’s already-compressed source, as read back verbatim from an imported file – None for a module created fresh in this session (nothing to cache yet). set_vba_module_source clears this whenever source is replaced. Export reuses the cached bytes instead of recompressing source from scratch for every module untouched by the CRUD operation that triggered the save.

Implementations§

Source§

impl VbaModule

Source

pub fn check_syntax(&self) -> Result<ModuleSyntax, Error>

Checks this module’s source, naming it in any error.

The name matters more than it looks: a workbook can hold many modules and visi macro check reports on all of them, so an error that does not say which one it came from is close to useless.

A VbaModule does not know its project, so unlike the free check_syntax this cannot conclude anything from a name it fails to resolve – a sibling module may well declare it. Reach for VbaProject::check_modules when the project is available; it is strictly the better check.

Source§

impl VbaModule

Source

pub fn is_document(&self) -> bool

Whether this is a document module – ThisWorkbook or a worksheet’s code-behind – as opposed to a standard or class module.

Trait Implementations§

Source§

impl Clone for VbaModule

Source§

fn clone(&self) -> VbaModule

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VbaModule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for VbaModule

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for VbaModule

Source§

fn eq(&self, other: &VbaModule) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for VbaModule

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for VbaModule

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V