agentic-net-examples / vba-macros
AGENTS.md4 starsChanged 3 months agoMITView on GitHub
Verified C# examples for vba-macros scenarios in Aspose.Words for .NET
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository29 other files it gives its agents.
- aspose-words-examplesAGENTS.md
- barcode-imageAGENTS.md
- chartsAGENTS.md
- commentsAGENTS.md
- comparisonAGENTS.md
- content-controlAGENTS.md
- conversionAGENTS.md
- extractionAGENTS.md
- find-and-replaceAGENTS.md
- fontsAGENTS.md
- form-fieldsAGENTS.md
- hyphenationAGENTS.md
- imagesAGENTS.md
- join-documentsAGENTS.md
- linq-reportingAGENTS.md
- listsAGENTS.md
- mail-mergeAGENTS.md
- officemathAGENTS.md
- ole-objectsAGENTS.md
- paragraphsAGENTS.md
- programming-with-documentsAGENTS.md
- rangeAGENTS.md
- renderingAGENTS.md
- security-and-protectionAGENTS.md
- shapesAGENTS.md
- split-documentAGENTS.md
- track-changesAGENTS.md
- watermarkAGENTS.md
- working-with-tableAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Always use documented Aspose.Words APIs directly.
- Distinctive: line 18
Always create local macro-enabled sample documents when a task refers to an existing file, folder, stream, template, or input asset.
- Distinctive: line 20
Keep validation narrow and task-specific.
- Distinctive: line 21
Do not invent VBA or reference helper APIs.
- Distinctive: line 27
Use the simplest workflow that satisfies the task.
- Distinctive: line 260
When replacing a file, prefer the latest verified publish-ready version rather than a merely compiling draft.
- Distinctive: line 261
Keep examples standalone, bootstrap missing inputs locally, and prefer documented Aspose APIs over speculative shortcuts.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md - VBA Macros
Purpose
This folder is a live, curated example set for VBA Macros scenarios. Treat every .cs file as a standalone console application. The goal is correct, warning-free examples that use documented Aspose APIs and match the original task intent.
Non-negotiable conventions
- Always use documented Aspose.Words APIs directly.
- Always create local macro-enabled sample documents when a task refers to an existing file, folder, stream, template, or input asset.
- Save macro content in macro-enabled formats such as
DOCMorDOTM. - Keep validation narrow and task-specific.
- Do not invent VBA or reference helper APIs.
Recommended workflow selection
- Vba Workflow workflow: 34 examples
Use the simplest workflow that satisfies the task.
Validation priorities
- The code must compile and run without manual input.
- API usage must be supported by the configured package versions.
- Exported outputs must actually be written by the example.
- Validation scenarios must inspect only the behavior requested by the task.
- Examples that depend on files, folders, streams, images, or data should bootstrap those inputs locally during the example run.
File-to-task reference
load-a-docx-file-containing-vba-macros-and-enumerate-all-modules-in-the-vbaproject.cs- Task: Load a DOCX file containing VBA macros and enumerate all modules in the VbaProject.
- Workflow: vba-workflow
- Outputs: docx, doc
- Selected engine: mcp
validate-that-a-loaded-document-s-vbaproject-contains-at-least-one-module-before-attemptin.cs- Task: Validate that a loaded document's VbaProject contains at least one module before attempting modifications.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
enumerate-vbaproject-references-filter-out-com-references-and-log-remaining-references-to.cs- Task: Enumerate VbaProject.References, filter out COM references, and log remaining references to console.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
retrieve-the-source-code-of-a-specific-vbamodule-and-write-it-to-a-text-file-for-analysis.cs- Task: Retrieve the source code of a specific VbaModule and write it to a text file for analysis.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
iterate-through-all-vbamodules-in-a-document-and-replace-deprecated-api-calls-with-updated.cs- Task: Iterate through all VbaModules in a document and replace deprecated API calls with updated equivalents.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
perform-a-case-insensitive-search-across-all-vba-modules-for-deprecated-function-names-and.cs- Task: Perform a case-insensitive search across all VBA modules for deprecated function names and replace them.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
replace-hard-coded-file-paths-in-macro-source-code-with-relative-paths-using-string-manipu.cs- Task: Replace hard-coded file paths in macro source code with relative paths using string manipulation functions.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
update-the-sourcecode-of-a-vbamodule-to-include-error-handling-using-on-error-resume-next.cs- Task: Update the SourceCode of a VbaModule to include error handling using On Error Resume Next statements.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
iterate-through-all-vbamodules-prepend-a-comment-header-containing-author-and-date-informa.cs- Task: Iterate through all VbaModules, prepend a comment header containing author and date information to each source code.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
add-error-logging-code-to-each-vba-module-by-inserting-a-standardized-logging-routine-at-t.cs- Task: Add error logging code to each VBA module by inserting a standardized logging routine at the beginning.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
create-a-new-vbaproject-add-a-standard-module-and-assign-custom-macro-code-to-its-sourceco.cs- Task: Create a new VbaProject, add a standard module, and assign custom macro code to its SourceCode property.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
create-a-vba-project-with-a-class-module-define-a-public-method-and-invoke-it-from-another.cs- Task: Create a VBA project with a class module, define a public method, and invoke it from another module.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
add-a-reference-to-the-microsoft-excel-object-library-in-a-vbaproject-and-verify-its-prese.cs- Task: Add a reference to the Microsoft Excel Object Library in a VbaProject and verify its presence.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
add-a-reference-to-the-microsoft-scripting-runtime-library-and-use-its-dictionary-object-w.cs- Task: Add a reference to the Microsoft Scripting Runtime library and use its Dictionary object within a macro.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
add-a-reference-to-a-custom-com-library-then-call-its-methods-from-a-newly-added-vba-modul.cs- Task: Add a reference to a custom COM library, then call its methods from a newly added VBA module.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
remove-an-existing-reference-from-a-vbaproject-s-references-collection-and-confirm-the-ref.cs- Task: Remove an existing reference from a VbaProject's References collection and confirm the reference count decreases.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
remove-all-standard-modules-from-a-vbaproject-leaving-only-class-modules-and-save-the-docu.cs- Task: Remove all standard modules from a VbaProject, leaving only class modules, and save the document.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
clone-the-entire-vba-project-from-one-word-document-to-another-and-save-the-target-documen.cs- Task: Clone the entire VBA project from one Word document to another and save the target document.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
use-the-clonevbaproject-method-to-duplicate-a-vba-project-while-preserving-module-order-an.cs- Task: Use the CloneVbaProject method to duplicate a VBA project while preserving module order and references.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
clone-a-vba-project-from-a-template-document-into-newly-generated-reports-to-ensure-consis.cs- Task: Clone a VBA project from a template document into newly generated reports to ensure consistent macros.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
clone-a-vba-project-then-remove-all-references-to-external-libraries-to-create-a-self-cont.cs- Task: Clone a VBA project, then remove all references to external libraries to create a self-contained macro set.
- Workflow: vba-workflow
- Outputs: docm
- Selected engine: mcp
copy-a-single-vbamodule-from-a-source-document-s-vba-project-into-a-destination-document-s.cs- Task: Copy a single VbaModule from a source document's VBA project into a destination document's project.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
load-a-docx-file-create-a-new-vba-project-and-copy-selected-modules-from-another-document.cs- Task: Load a DOCX file, create a new VBA project, and copy selected modules from another document into it.
- Workflow: vba-workflow
- Outputs: docx, doc
- Selected engine: mcp
use-a-configuration-file-to-specify-which-vba-modules-to-copy-between-documents-during-bat.cs- Task: Use a configuration file to specify which VBA modules to copy between documents during batch processing.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
import-a-vba-module-from-an-external-bas-file-into-a-document-s-vbaproject-and-set-its-nam.cs- Task: Import a VBA module from an external .bas file into a document's VbaProject and set its name.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
import-macro-definitions-from-a-json-file-create-corresponding-vbamodules-and-assign-their.cs- Task: Import macro definitions from a JSON file, create corresponding VbaModules, and assign their source code.
- Workflow: vba-workflow
- Outputs: json
- Selected engine: mcp
export-all-vba-modules-from-a-document-to-a-zip-archive-maintaining-original-module-filena.cs- Task: Export all VBA modules from a document to a ZIP archive, maintaining original module filenames.
- Workflow: vba-workflow
- Outputs: doc, zip
- Selected engine: mcp
export-macro-source-code-to-json-format-including-module-names-and-code-strings-for-extern.cs- Task: Export macro source code to JSON format, including module names and code strings, for external processing.
- Workflow: vba-workflow
- Outputs: json
- Selected engine: mcp
load-multiple-docm-files-in-a-batch-extract-each-macro-s-source-code-and-store-them-in-sep.cs- Task: Load multiple DOCM files in a batch, extract each macro's source code, and store them in separate files.
- Workflow: vba-workflow
- Outputs: docm, doc
- Selected engine: mcp
batch-process-a-folder-of-docm-files-extracting-macro-names-and-writing-them-to-a-csv-summ.cs- Task: Batch process a folder of DOCM files, extracting macro names and writing them to a CSV summary file.
- Workflow: vba-workflow
- Outputs: docm, doc, csv
- Selected engine: mcp
compare-the-source-code-of-two-vbamodules-from-different-documents-and-generate-a-diff-rep.cs- Task: Compare the source code of two VbaModules from different documents and generate a diff report.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
generate-a-documentation-report-listing-each-vba-module-its-type-and-the-number-of-lines-o.cs- Task: Generate a documentation report listing each VBA module, its type, and the number of lines of code.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
load-a-docx-file-add-a-new-vba-module-that-automates-table-formatting-and-save-the-updated.cs- Task: Load a DOCX file, add a new VBA module that automates table formatting, and save the updated document.
- Workflow: vba-workflow
- Outputs: docx, doc
- Selected engine: mcp
use-the-document-vbaproject-property-to-replace-an-existing-vba-project-with-a-pre-configu.cs- Task: Use the Document.VbaProject property to replace an existing VBA project with a pre-configured project template.
- Workflow: vba-workflow
- Outputs: doc
- Selected engine: mcp
Common failure patterns and preferred agent fixes
- Unsupported API invention
- Symptom: Generated code references members that do not exist in the selected package version.
- Preferred fix: Replace invented members with documented Aspose.Words APIs already proven in this category.
- Missing local bootstrap inputs
- Symptom: The example assumes source files, folders, images, or data already exist.
- Preferred fix: Create deterministic local inputs before loading, processing, or validating them.
- Over-broad validation
- Symptom: The example fails at runtime while checking unrelated document internals.
- Preferred fix: Validate only the requested behavior and the existence of expected outputs.
Build and run contract
- Target framework:
net8.0 - Package:
Aspose.Words26.9.0
Command reference
Create a temporary console project
dotnet new console -n ExampleProject --framework net8.0
cd ExampleProjectAdd required packages
dotnet add package Aspose.Words --version 26.9.0Copy a category example into the temp project
Copy-Item ..\vba-macros\<example-file>.cs .\Program.csBuild and run
dotnet build --configuration Release --verbosity minimal
dotnet run --configuration Release --no-buildCategory update guidance
- Preserve file-to-task traceability. Any future update should keep the original task text associated with the file in metadata.
- When replacing a file, prefer the latest verified publish-ready version rather than a merely compiling draft.
- Keep examples standalone, bootstrap missing inputs locally, and prefer documented Aspose APIs over speculative shortcuts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

