Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim oExcel As Excel.ApplicationClass
Dim oBook As Excel.WorkbookClass
Dim oBooks As Excel.Workbooks
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\Excel.xls")
'Run the macros.
oExcel.Run("Macro1")
'Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
Partial Class Default9
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oExcel As Excel.ApplicationClass
Dim oBook As Excel.WorkbookClass
Dim oBooks As Excel.Workbooks
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\ABC.xls")
'Run the macros.
oExcel.Run("Macro3")
'Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
End Sub
End Class
Thanks. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
Error 2 Statement cannot appear within a method body. End of method assumed. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\684a4ea2\d3967a01\App_Web_vi5qxpvi.1.vb 89
Thanks. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
In ur Project Add Reference then in COM Components tab Select Microsodt Excel 12.0 object library
After that paste this in ur code
import this line
Imports
Microsoft.Office.Interop
and this is the page load
Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.Load
Dim oExcel
As Excel.ApplicationClass
Dim oBook
As Excel.WorkbookClass
Dim oBooks
As Excel.Workbooks
'Start Excel and open the workbook.
oExcel = New Excel.ApplicationClass
oExcel.Visible =
True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\InputSheet-M.xls")
'Run the macros.
oExcel.Run("Macro3")
'Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
Thanks. In my COM tab there is only Excel 9.0 no Excel 12.0
I download the Office XP Primary Interop Assemblies and browse to and selected Microsoft.Office.Interop.Excel.dll
Still get same error...
How to get Excel12 .dll ??
Thanks
Thanks. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 05:18 AM|LINK
Your End Sub is Missing!!!!!
Contact me
hkbeer
Member
707 Points
1453 Posts
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 05:28 AM|LINK
Thanks. Actually my "End Sub" is actually there. I just did not copy it out here.
So, must be something else....
Help.
www.developerfusion.com/tools/convert/csharp-to-vb/
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 05:40 AM|LINK
add a new aspx Page with code behind .vb file
in the code behind copy the pageload event
and in the top write
imports Interop.Excel
Contact me
hkbeer
Member
707 Points
1453 Posts
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 07:46 AM|LINK
Thanks. Have tried but no luck. Have you tried it on your machine?.
www.developerfusion.com/tools/convert/csharp-to-vb/
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 07:55 AM|LINK
No not yet. I will have to install office components. Then I can do meanwhile can u paste ur .vb file code
Contact me
hkbeer
Member
707 Points
1453 Posts
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 08:01 AM|LINK
Thanks. My vb code:-
=================
Imports Excel
Partial Class Default9
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oExcel As Excel.ApplicationClass
Dim oBook As Excel.WorkbookClass
Dim oBooks As Excel.Workbooks
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\ABC.xls")
'Run the macros.
oExcel.Run("Macro3")
'Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
End Sub
End Class
www.developerfusion.com/tools/convert/csharp-to-vb/
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 08:10 AM|LINK
Also give me the error messge that u get and if its a exception complete stack trace
Contact me
hkbeer
Member
707 Points
1453 Posts
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 08:30 AM|LINK
Error 2 Statement cannot appear within a method body. End of method assumed. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\684a4ea2\d3967a01\App_Web_vi5qxpvi.1.vb 89
www.developerfusion.com/tools/convert/csharp-to-vb/
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 08:50 AM|LINK
In ur Project Add Reference then in COM Components tab Select Microsodt Excel 12.0 object library
After that paste this in ur code
import this line
Imports
Microsoft.Office.Interopand this is the page load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim oExcel As Excel.ApplicationClass Dim oBook As Excel.WorkbookClass Dim oBooks As Excel.Workbooks 'Start Excel and open the workbook. oExcel = New Excel.ApplicationClassoExcel.Visible =
TrueoBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\InputSheet-M.xls") 'Run the macros. oExcel.Run("Macro3")
'Clean-up: Close the workbook and quit Excel. oBook.Close(False)System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook =
NothingSystem.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks =
NothingoExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
End Subits running fine for me
Contact me
hkbeer
Member
707 Points
1453 Posts
Re: How to run a Macro of an Excel file opened on web server
Jan 03, 2009 08:58 AM|LINK
Thanks. In my COM tab there is only Excel 9.0 no Excel 12.0
I download the Office XP Primary Interop Assemblies and browse to and selected Microsoft.Office.Interop.Excel.dll
Still get same error...
How to get Excel12 .dll ??
Thanks
www.developerfusion.com/tools/convert/csharp-to-vb/