使用Vb.net导出VBA宏

时间:2014-01-25 17:22:38

标签: vb.net excel-vba excel-interop vba excel

我有以下情况:

一方面,我有Vb.net个应用程序,我可以从中访问/运行存储在Excel工作簿(*.xlsm)中的宏。感谢Microsoft.Office.Interop.Excel没什么大不了的。

我可以通过xl.App.Run(macroname)或甚至参数来访问宏。

现在我想查看/解析宏本身的代码以进一步分析它们 - 有没有办法?

2 个答案:

答案 0 :(得分:0)

如果您可以从VB.NET运行Excel VBA宏,那么您可以运行此处描述的Ron de Bruin代码:

Import and Export VBA Code

答案 1 :(得分:0)

dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
相关问题