ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   programatically accessing Macros in worksheets (https://www.excelbanter.com/excel-programming/295226-programatically-accessing-macros-worksheets.html)

Patrick[_8_]

programatically accessing Macros in worksheets
 
We have a vendor that has supplied an excel spreadsheet. Information
entered on the spreadsheet is uploaded to web application. We want to
automate some of these features.

I have a .net application that will open the workbook. Within the work
book there are 5 worksheets with macros and constants within them. I
can access the macros at a workbook level with the following example:

My question is.....can you access the worksheet macros and constants
from a .net application? I have tried several variations of the
xlapp.run. Being able to access variables and the procedures within
the functions would be a big benefit. Thanks for your help!

Sub Main()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim szResult As String
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open("E:\Book1.xls")
szResult = xlApp.Run("Book1.xls!MyFunc", 10, "Some String")
MsgBox szResult
xlBook.Close False
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub

Jim Rech

programatically accessing Macros in worksheets
 
This syntax works for running sheet code from another workbook in Excel.
Perhaps you can adapt it to your situation.

Run "book1.xls!Sheet1.Sheet1Macro"

--
Jim Rech
Excel MVP
"Patrick" wrote in message
om...
| We have a vendor that has supplied an excel spreadsheet. Information
| entered on the spreadsheet is uploaded to web application. We want to
| automate some of these features.
|
| I have a .net application that will open the workbook. Within the work
| book there are 5 worksheets with macros and constants within them. I
| can access the macros at a workbook level with the following example:
|
| My question is.....can you access the worksheet macros and constants
| from a .net application? I have tried several variations of the
| xlapp.run. Being able to access variables and the procedures within
| the functions would be a big benefit. Thanks for your help!
|
| Sub Main()
| Dim xlApp As Excel.Application
| Dim xlBook As Excel.Workbook
| Dim szResult As String
| Set xlApp = New Excel.Application
| Set xlBook = xlApp.Workbooks.Open("E:\Book1.xls")
| szResult = xlApp.Run("Book1.xls!MyFunc", 10, "Some String")
| MsgBox szResult
| xlBook.Close False
| Set xlBook = Nothing
| xlApp.Quit
| Set xlApp = Nothing
| End Sub




All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com