linexcel.vba¶
linexcel.vba ¶
Extraction and static lineage of embedded VBA code.
Extraction relies on oletools (olevba). Analysis is static and deliberately heuristic: it identifies procedures, the internal call graph, and cell/range access expressed literally (Range("A1"), Cells(2, 3), [A1:B4], Worksheets("X").Range(...)).
VbaRef
dataclass
¶
extract_vba_modules ¶
extract_vba_modules(
data: bytes,
filename: str,
warnings: list[str] | None = None,
*,
provenance: dict[str, dict] | None = None,
) -> dict[str, str]
Extract {module_name: code} via olevba.
A workbook holding no macro yields an empty mapping, and so did every
failure below: an unreadable VBA project, a module stream olevba chokes on,
oletools missing altogether. The report then showed a macro workbook as
having no code at all and said nothing about it, so the one reading it
cannot tell "no macros" from "we could not read them". Every such reason is
therefore appended to warnings when a list is given.
A failure part-way through keeps the modules already read. Their procedures and call graph are real, and the warning says the rest is missing; dropping them would trade a partial answer for none.
olevba dispatches on the file's own header rather than on filename, so
a macro workbook is found whatever it is called, including the default name
:func:linexcel.analyze gives a workbook handed to it as bytes.
Source code in src/linexcel/vba.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
analyze_vba ¶
Full static analysis: procedures, range access, call graph.