Last active
October 11, 2025 15:23
-
-
Save aspose-com-kb/f85dc044e65bc4e01a40355ce0d4fdfe to your computer and use it in GitHub Desktop.
Edit Macro in Word using C#. For details: https://kb.aspose.com/words/net/edit-macro-in-word-using-csharp/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Aspose.Words; | |
using Aspose.Words.Vba; | |
namespace AsposeWordsVbaDemo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Document docm = new Document("CreateVbaProject.docm"); | |
VbaProject project = docm.VbaProject; | |
const string newSourceCode = | |
@"Sub HelloAspose() | |
MsgBox ""Hello! The VBA code is modified!"" | |
End Sub"; | |
project.Modules[1].SourceCode = newSourceCode; | |
docm.Save("updated.docm"); | |
Console.WriteLine("Macro code modified."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment