V
villains32
Hello,
I am working on a ASP.NET app written in VB.net. I am attempting to import
an Excel Macro module into an excel workbook.
I am able to run the macro if it is already in the workbook but this
workbook will be created on the fly and this macro needs to be integrated in.
My current code is:
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oModule As VBIDE.VBComponent
exportPath = "c:\Inetpub\wwwRoot\TT\Reports\" &
TTUser.GetUserNameFromID(TTSecurity.GetUserID) & "\"
webPath = "/TT/Reports/" & TTUser.GetUserNameFromID(TTSecurity.GetUserID)
myFileName = webPath & "/Excel.xls"
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oBooks = oExcel.Workbooks
oBook = oBooks.Open(exportPath & "Excel.xls")
oBook.Application.VBE.ActiveVBProject.VBComponents.Import(exportPath &
"Module1.bas")
oExcel.Run("ParseData") 'Run the macros.
oBook.SaveAs(exportPath & "Excel.xls") 'Save in a temporary file
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = myContentType
Response.Redirect(myFileName) 'Send the user to the file
Response.Flush()
Response.Close()
My code bombs on:
oBook.Application.VBE.ActiveVBProject.VBComponents.Import(exportPath &
"Module1.bas")
It gives me this message: System.Runtime.InteropServices.COMException:
Programmatic access to Visual Basic Project is not trusted
Now I have done some research and it has told me to check the box for Trust
access to Visual Basic Project.
I was sure this would solve the problem but I still get the same error.
I am running Windows XP, Excel 2003 and VS.NET 2003.
Any suggestions would be greatly appreciated.
I am working on a ASP.NET app written in VB.net. I am attempting to import
an Excel Macro module into an excel workbook.
I am able to run the macro if it is already in the workbook but this
workbook will be created on the fly and this macro needs to be integrated in.
My current code is:
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oModule As VBIDE.VBComponent
exportPath = "c:\Inetpub\wwwRoot\TT\Reports\" &
TTUser.GetUserNameFromID(TTSecurity.GetUserID) & "\"
webPath = "/TT/Reports/" & TTUser.GetUserNameFromID(TTSecurity.GetUserID)
myFileName = webPath & "/Excel.xls"
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oBooks = oExcel.Workbooks
oBook = oBooks.Open(exportPath & "Excel.xls")
oBook.Application.VBE.ActiveVBProject.VBComponents.Import(exportPath &
"Module1.bas")
oExcel.Run("ParseData") 'Run the macros.
oBook.SaveAs(exportPath & "Excel.xls") 'Save in a temporary file
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = myContentType
Response.Redirect(myFileName) 'Send the user to the file
Response.Flush()
Response.Close()
My code bombs on:
oBook.Application.VBE.ActiveVBProject.VBComponents.Import(exportPath &
"Module1.bas")
It gives me this message: System.Runtime.InteropServices.COMException:
Programmatic access to Visual Basic Project is not trusted
Now I have done some research and it has told me to check the box for Trust
access to Visual Basic Project.
I was sure this would solve the problem but I still get the same error.
I am running Windows XP, Excel 2003 and VS.NET 2003.
Any suggestions would be greatly appreciated.