1

i have a one 2003 excel file. using ofc.exe file i have converted the 2003 excel file in to 2007 exls file.

now my problem is before convert the file can i know the excel file is a macro excel file in c#.net ?

Edwin de Koning
  • 14,209
  • 7
  • 56
  • 74
Suresh Chaudhary
  • 1,609
  • 5
  • 25
  • 40

1 Answers1

2

Reading up on this answer I found that using Application.VBE.ActiveVBProject.VBComponent seems to be what you want.

A similar question was asked on the MSDN forums albeit that one concerns Visio not Excel. I'm sure you can adapt the code accordingly.

Further on this SO question asks exactly the same as you do. Albeit this answers does not seem to cover C#...

Over at the eggheadcafe one user suggests using this code snippet to loop through all VB-components:

Sub Test()
  If bHasMacros(ActiveWorkbook) Then
    MsgBox ActiveWorkbook.Name & " has macros."
  End If
End Sub

Function bHasMacros(ByRef wkbBook As Workbook) As Boolean
  Dim cmpComponent As VBIDE.VBComponent
  For Each cmpComponent In wkbBook.VBProject.VBComponents
    If cmpComponent.CodeModule.CountOfLines > 1 Then
      bHasMacros = True
      Exit Function
    End If
  Next cmpComponent
End Function
Community
  • 1
  • 1
froeschli
  • 2,692
  • 2
  • 28
  • 55