|
-
August 12th, 2012, 10:13 PM
#1
Writing into Excel VBA from Dot net code
I have a Dot Net application which launches MS Access. I am able to write the values into excel also.
But I need to add Macro for the excel to calculate, save etc.
Normally the VBA editor opens up in Excel when Alt-F11 is pressed.
There are a few Subroutines inside the VBA editor as follows:
Private Sub Worksheet_Calculate()
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
Now from my dot net code I want to write into these methods. How can I do that. May be I need to create a separate function also inside the VBA editor.
Thanks in advance.
-
August 13th, 2012, 01:34 PM
#2
Re: Writing into Excel VBA from Dot net code
Hi,
I'm not sure if this is what you're looking for. If you just want run a macro in a saved wookbook try this...
Code:
Dim ExcelApp As Excel.Application
Dim MySheet As Excel.Worksheet
Dim MyBook As Excel.Workbook
Try
ExcelApp = New Excel.Application
ExcelApp.UserControl = True
ExcelApp.Visible = True
ExcelApp.Workbooks.Open("C:\Temp\Book1.xlsm", False, True)
MyBook = ExcelApp.ActiveWorkbook
MySheet = MyBook.Worksheets(1)
MySheet.Activate()
ExcelApp.Application.Run("Book1.xlsm!Macro1")
Catch ex As Exception
End Try
Curt
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
|