Running Excel Macro from VB

jakobusbenne

New member
Joined
Oct 3, 2007
Messages
3
Programming Experience
1-3
Hi,

I just migrated to vb, am using .net 2003 as well as Excel 2007. Currently I'm trying to execute a Excel Macro (called ChartMacro) from VB. Everything works fine until I try to execute the Macro: objExcel.RUn("ChartMacro") --> giving me the error message that "Cannot run the macro 'ChartMacro.ChartMacro'. The macro may not be available in this workbook or all macros may be disabled."

I have no idea as to why i get this message - any explanation, tips etc are welcome. Thanks in advance :)

Code as follows:
VB.NET:
Dim objExcel As New Microsoft.Office.Interop.Excel.Application
        objExcel.Visible = True
        objExcel.Workbooks.Add() '("c:/Inv_Norm_Dist_Calc.xls") 'last part open a template that it use

        Dim Z_Value(15) As Double
        For i As Integer = 1 To 8
            'Place the different values in the excell cells
            objExcel.Range("A" & i).Select()
            objExcel.Range("B1" & i).Activate()
        Next

        'Start Excel and open the workbook.
        objExcel.Workbooks.Open(Filename:="C:\Users\Jakobus\Documents\Book1.xlsx", ReadOnly:=True)
        objExcel.Run("ChartMacro.ChartMacro")


        objExcel.ActiveWorkbook.Close(SaveChanges:=False)

        ' Quit Excel
        objExcel.Quit()

        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objExcel)
        objExcel = Nothing
 
Last edited by a moderator:
Visual Basic for Applications (VBA) is disabled by default in Excel 2007. Also check the Macro secuirty settings.
 

Latest posts

Back
Top