|
-
Aug 2nd, 2001, 07:40 AM
#1
Thread Starter
Addicted Member
Launching Excel from VB
Is it possible to launch excel from VB and execute a macro ?
-
Aug 2nd, 2001, 08:01 AM
#2
Hyperactive Member
Select Microsoft Excel 8.0 Object Library in the Project references.
Do something like...
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
Set objExcel = New Excel.Application
Set objBook = objExcel.Workbooks.Add
objExcel.Visible = True
objBook.Sheets(1).Cells(1,1).Value = "HELLO"
objBook.Sheets(1).Cells(1,1).Font.Bold = True
Etc...
Remember to Quit Excel after use and set objects to nothing to avoid sessions being left open in the background as VB gets upset. Not sure about executing a pre-written macro as I've always programmed what I need to do in VB.
PS I have a question.
Has anybody tried to close down an Excel application when a chart object has been created in a workbook which has been saved and closed.
I found out that the chart object keeps a link to the cell range that is the chart source data. This prevents Excel from closing properly.
The way I got round this was to use GetObject and a loop, and close any applications that were lingering - any other ideas??
-
Aug 2nd, 2001, 08:05 AM
#3
Fanatic Member
That certainly shows you how to openexcel. As for running Excel Macros, try:
Code:
Dim xls As New Excel.Application
Dim wrk As Excel.Workbook
Set wrk = xls.Workbooks.Open("c:\MySheet.xls")
xls.Run "MyMacro"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|