codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  execute an Excel macro when the sheet is changed from ASP.NET  aparna at 21:25 on Wednesday, February 09, 2005
 

Hello,

I am facing problem in writing to an Excel file from ASP.NET. I want to change the value of a cell (B7) on the button click from ASP.NET web enabled browser. Following is the code of my ASP.NET web application:

<%@ Page Language="VB" Debug="true" %>
<script runat="server">

' write_to_plc.aspx
'
Private m_sConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""

Sub Button1_Click(sender As Object, e As EventArgs)

Update_Individual_Cells()

End Sub

Public Sub Update_Individual_Cells()

'==========================================================================
' Update individual cells on the PlcData worksheet;
' specifically, cell B7 is modified.
'==========================================================================

' NOTE: The connection string indicates that the table does *NOT*
' have a header row.
Dim conn As New System.Data.OleDb.OleDbConnection(m_sConn1.Replace("HDR=YES", "HDR=NO"))
conn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand()
cmd.Connection = conn

'Updates a cell B7 of the spreadsheet, PlcData to "1".
cmd.CommandText = "UPDATE [PlcData$B7:B7] SET F1 = '1'"
cmd.ExecuteNonQuery()

conn.Close()

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
Click this button to start an experiment:<button id="Button1" style="WIDTH: 100px; HEIGHT: 25px; BACKGROUND-COLOR: #e6e6fa" type="button" runat="server" onserverclick="Button1_Click">Click</button>
</form>
</body>
</html>

I want to get an Excel macro executed, when a cell value is changed. So, I wrote the following macro in “ThisWorkbook” of test.xls file:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Msgbox “hello”
End Sub

So, whenever the cell value is changed from 0 to 1, this macro should get executed.

The problem is that the ASP.NET web application updates the value from 0 to 1, but the macro doesn’t get executed until I open the file manually.

Can someone please fix this?

I tried another thing … I kept the excel file open prior to executing ASP.NET code. It gives me error message: The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.

I do not know about how to fix this either.

It will be great, if someone could help me with this. I appreciate your help.

Thanks,
Aparna









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  validation of two text fields on a search page
•  validation of two text fields on a search page
•  Re: iframe targeting
•  Re: javascript to validate an entry is in URL format.
•  How to retrieve file from hard disk and display on a list?
•  Isolating Memory Leaks
•  DirectShow: Help me debug please
•  DirectShow: Help me debug please
•  How to dynamically create a calendar when I click a button?


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005