Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
what exactly prevents INDIRECT from accessing closed worksheets? z.entropic Excel Worksheet Functions 3 July 24th 07 03:02 PM
Accessing Macros opieandy Excel Discussion (Misc queries) 9 May 23rd 07 10:55 PM
accessing rows with macros Sam Excel Discussion (Misc queries) 3 April 18th 05 11:56 PM
accessing worksheets greg Excel Worksheet Functions 2 November 2nd 04 03:53 PM
Programatically adding worksheets to a spreadsheet Scott Lyon Excel Programming 4 August 8th 03 02:54 PM


All times are GMT +1. The time now is 07:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"