Using Macros in Csharp
Using Macros in Csharp
Reader { public class OpenWorkbook { public void Open(string fileName) { var excel = new Excel.Application(); var workbook = excel.Workbooks.Open(fileName, false, true, Type.Missing , Type.Missing, Type.Missing, true, Type.Missing, Type.Missing, false, false, Ty pe.Missing, false, true, Type.Missing); var project = workbook.VBProject; var projectName = project.Name; var procedureType = Microsoft.Vbe.Interop.vbext_ProcKind.vbext_pk_Proc; foreach (var component in project.VBComponents) { VBA.VBComponent vbComponent = component as VBA.VBComponent; if (vbComponent != null) { string componentName = vbComponent.Name; var componentCode = vbComponent.CodeModule; int componentCodeLines = componentCode.CountOfLines; int line = 1; while (line < componentCodeLines) { string procedureName = componentCode.get_ProcOfLine(line, out procedureType); if (procedureName != string.Empty) { int procedureLines = componentCode.get_ProcCountLines(proce dureName, procedureType); int procedureStartLine = componentCode.get_ProcStartLine(pr ocedureName, procedureType); int codeStartLine = componentCode.get_ProcBodyLine(procedur eName, procedureType); string comments = "[No comments]"; if (codeStartLine != procedureStartLine) { comments = componentCode.get_Lines(line, codeStartLine procedureStartLine); } int signatureLines = 1; while (componentCode.get_Lines(codeStartLine, signatureLine s).EndsWith("_")) { signatureLines++; } string signature = componentCode.get_Lines(codeStartLine, s ignatureLines); signature = signature.Replace("\n", string.Empty); signature = signature.Replace("\r", string.Empty); signature = signature.Replace("_", string.Empty);