Excel / excel macros created within Visual Basic 
Author Message
 Excel / excel macros created within Visual Basic

I am trying to create an excel workbook with Macro's
programmatically from within a VB dll.  I can get the
program to work correctly, creating the .xls file with the
macro included when I run VB within the Debug
environment.  When I run outside of the VB environment, I
get the following error on the

"Set prrf_Module = prrf_Workbook.VBProject.VBComponents.Add
(1)" statement.

A component error has occurred, please contact your system
Error Number: 32796
Error Source: wmPRRF.dll:cBuildReport:BuildXLSReport
Error Description: Application-defined or object-defined
Note:  I have project references set for:

        Microsoft Excel  9.0 Object Library
        Microsoft Visual Basic for Applications
Extensibility 5.3

Here are the relevant pieces of my code.

    Dim prrf_Excel As Object
    Set prrf_Excel = CreateObject("Excel.Application")

    Dim prrf_Workbook As Object
    Dim prrf_worksheets As Object
    Dim prrf_Module As Object

    prrf_Excel.SheetsInNewWorkbook = 2
    Set prrf_Workbook = prrf_Excel.Workbooks.Add
    Set prrf_worksheets = prrf_Workbook.Worksheets(1)
        '*** worksheet formatting code ***
    Set prrf_worksheets = prrf_Workbook.Worksheets(2)
        '*** worksheet formatting code ***

'*** line of code causing error ***
    Set prrf_Module =
'*** line of code causing error ***

     strMacro = _
        "Private Sub prrf_Workbook_setPage()" & vbCr & _
            "***Macro code ****"

    prrf_Module.CodeModule.AddFromString strMacro
    prrf_Excel.Run "prrf_Workbook_setPage"
    prrf_Workbook.Close SaveChanges:=True,
FileName:=gstrRptPath, RouteWorkbook:=False

This code is pretty much cloned from the Microsoft
Knowledge Base article 194611 which addresses how to
create and call an excel macro programmatically from VB.  
Like I said, this it all works correctly within the Visual
Basic debug environment.

Tue, 13 Sep 2005 08:56:12 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Excel 2000 crashes when running macros created in Excel 97

2. Viewing Excel Files within Visual Basic 6

3. Visual Basic Macros in Excel

4. Changing Paper Size in Excel Visual Basic Macro

5. Running a Visual Basic Excel Macro from Program Manager Icon ***Help***

6. microsoft excel 4.0 macros coversion to excel 5.0 macros

7. Executing Excel Macros inside Visual Basic 4.0

8. Excel 5.0 Visual Basic Macros and Networks

9. Use of Excel functions in visual basic functions in excel module

10. looking for conversion software for MS Excel 4.0 (ELM) to MS Excel 5.0 visual Basic

11. Excel, creating columns and rows in Visual Basic

12. How to create a chart in Excel from Visual Basic


Powered by phpBB® Forum Software