Address a Macro thru the Excel object in VB.NET?

L

Lars Netzel

Is it possible to get to the macros at all in vb.net when reading an Excel
file?

I know theres something called MacroSheets.. but I don't understand how to
handle them

best regards
/Lars Netzel
 
P

Paul Clement

¤ Is it possible to get to the macros at all in vb.net when reading an Excel
¤ file?
¤
¤ I know theres something called MacroSheets.. but I don't understand how to
¤ handle them

I'm not sure what you mean by "get to the macros" but you can execute them:

How to run Office macros by using Automation from Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;306682


Paul
~~~~
Microsoft MVP (Visual Basic)
 
P

Paul Clement

¤ Can you alter them or remove them?
¤
¤ /Lars

Since this involves automation, you might post this question in microsoft.public.excel.programming.
I'm afraid I don't know of a way to modify the code modules programmatically.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
J

JR

try this


Sub sMakeMacroCode _

(ByVal wbBoek As Excel.Workbook, ByVal wsSheet As Excel.Worksheet, ByVal
sObject As String, ByVal sAction As String, ByVal sCode As String)

'Ex:sMakeMacroCode(objWB, "Blad1", "Worksheet", "Activate", Chr(9) &
"ActiveSheet.EnableAutoFilter = True")

Dim StartLine As Long, X As Byte

'wbBoek.Application.Visible = True

Try

With wbBoek.VBProject.VBComponents.Item(wsSheet.Index + 1).CodeModule

StartLine = .CreateEventProc(sAction, sObject) + 1

..InsertLines(StartLine, sCode)

X = wbBoek.VBProject.Protection

wbBoek.Application.VBE.MainWindow.Visible = False

'Close is beter than visible but won't work

End With

Catch ex As Exception

MsgBox("Fout: " & ex.Message)

End Try

End Sub 'sMakeMacroCode

its add some code to an workbook on the level worksheet

in excell 2002 or higher you need to allow editing the VBE

google on VBProject.VBComponents will find mmore info



Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top