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 ?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

but my application is in c#. how can i use this code? can you please suggest me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.