Running VBA code in EXcel from VB6 using EXcel Objects 
Author Message
 Running VBA code in EXcel from VB6 using EXcel Objects

I am instantiating an EXcel object in my VB6 Program.  I have a module of
VBA code from a database that I would like to run against the worksheet
currently instantiated.   How can I do this?


Sat, 23 Oct 2004 06:31:36 GMT  
 Running VBA code in EXcel from VB6 using EXcel Objects
Hi Tobe
Application.Run "TheNameOfYourMacroHere"
Regards
Pascal



Quote:
> I am instantiating an EXcel object in my VB6 Program.  I have a module of
> VBA code from a database that I would like to run against the worksheet
> currently instantiated.   How can I do this?



Sat, 23 Oct 2004 15:29:00 GMT  
 Running VBA code in EXcel from VB6 using EXcel Objects
How do I put the macro in.  Currently, the application doesn't know what the
macro is.  I am creating the spreadsheet on the fly and then want to create
and run a new macro (whose code is from a database) in the spreadsheet.

tlp


Quote:
> Hi Tobe
> Application.Run "TheNameOfYourMacroHere"
> Regards
> Pascal



> > I am instantiating an EXcel object in my VB6 Program.  I have a module
of
> > VBA code from a database that I would like to run against the worksheet
> > currently instantiated.   How can I do this?



Mon, 25 Oct 2004 06:09:26 GMT  
 Running VBA code in EXcel from VB6 using EXcel Objects
Take a look at the following KB article.  It shows how to add an run a VBA
macro programmatically.

Q219905 - HOWTO: Dynamically Add and Run a VBA Macro from Visual Basic
http://support.microsoft.com/support/kb/articles/q219/9/05.asp

Thanks,
Joel Alley

Of course, this posting wouldnt be complete without a nice, juicy
disclaimer from our lawyers:  This posting is provided AS IS with no
warranties, and confers no rights. You assume all risk for your use. ? 2002
Microsoft Corporation. All rights reserved.



Fri, 29 Oct 2004 23:39:14 GMT  
 Running VBA code in EXcel from VB6 using EXcel Objects
Thanks.

But can't one run the macro without without writing it to a file somewhere
first?  I am getting the text of the macro from a report database and it is
already in memory.

I prefer not to write out yet-another-file to clutter up the disk and I
would also like to avoid security issues.

tlp


Quote:
> Take a look at the following KB article.  It shows how to add an run a VBA
> macro programmatically.

> Q219905 - HOWTO: Dynamically Add and Run a VBA Macro from Visual Basic
> http://support.microsoft.com/support/kb/articles/q219/9/05.asp

> Thanks,
> Joel Alley

> Of course, this posting wouldn't be complete without a nice, juicy
> disclaimer from our lawyers:  This posting is provided "AS IS" with no
> warranties, and confers no rights. You assume all risk for your use. ?
2002
> Microsoft Corporation. All rights reserved.



Sat, 30 Oct 2004 14:24:28 GMT  
 Running VBA code in EXcel from VB6 using EXcel Objects
You might try something like:

Option Explicit

Private Sub Command1_Click()
    Dim xlApp As Excel.Application
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True

    xlApp.Workbooks.Add

    Dim myComponent As VBComponent
    Set myComponent =
xlApp.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_StdModule)
    myComponent.CodeModule.AddFromString _
        "Public Sub Test()" & vbCrLf & " MsgBox ""Hello, World!""" &  
vbCrLf & "End Sub"

    xlApp.Run "Test"

    xlApp.UserControl = True
    Set myComponent = Nothing
    Set xlApp = Nothing
End Sub

Thanks,
Joel Alley

Of course, this posting wouldnt be complete without a nice, juicy
disclaimer from our lawyers:  This posting is provided AS IS with no
warranties, and confers no rights. You assume all risk for your use. ? 2002
Microsoft Corporation. All rights reserved.



Sat, 30 Oct 2004 23:21:48 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Running excel add-in (added into excel - not access) in Access VBA

2. VBA code in Excel 97 vs Excel 2002

3. Compatibility Problem Using MS Excel 97 VBA on Excel 2000/XP - Causes crashes

4. running code from Access that runs code in an excel spreadsheet

5. Running an excel macro using excel 8 obj lib

6. Running an excel macro using excel 8 obj lib

7. Using Excel object without installing Excel?

8. Detecting EOF for Excel file using Excel Application Object

9. Problem in running Excel sort function in Access using VBA

10. Windows EXCEL VBA / MAC EXCEL VBA compatibility issues

11. Excel 97 VBA vs Excel 2000 VBA

12. Using VB (or VBA) to call code in multiple worksheets of an Excel app

 

 
Powered by phpBB® Forum Software