Excel / ActiveX help!

neilmonk

New Member
Joined
Jun 21, 2004
Messages
22
Right, where to start....!

Firstly, here's what I'm wanting to do:
Have a HTML page that has a form, which writes data to "somewhere".

Due to my ****tyy conmpany, and all the red tape, I do not have access to a webserver, so for those of you that say "get a webserver"; I'll thank you for your comments in advance ;-)

I've managed [eventually] to find a script that writes an Excel file, which is spot on, exactly what I wanted. The only problem is that it WRITES an excel file. I want it to UPDATE an excel file.

Here's the code:

Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function xlWrite(r,c) {
  var xlApp, xlSheet;
  xlApp = new ActiveXObject("Excel.Application");
  xlApp.Visible = true;
  xlApp.Workbooks.Add();
  xlSheet = xlApp.ActiveSheet;
  xlSheet.Cells(r,c).Value = frm.txt.value;
  xlSheet.SaveAs("C:\\xlText.xls");
  xlApp.Quit();
  xlApp = null;
  setTimeout("CollectGarbage()",1);
}
//  End -->
</script>
</HEAD>

<FORM NAME="frm">
  <INPUT TYPE="Text" NAME="txt" Value="Some cell text">

  <INPUT TYPE="Button" VALUE="Put in row 1, column 2" ONCLICK="xlWrite
(1,2)">
</FORM>

Also, to avoid the "File exists, overwrite (Yes,No)" dialog - use 
SaveCopyAs instead of SaveAs.

</HTML>

I then have an Excel file that has in it:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

rowcounter = 2
While Range("a" & rowcounter) <> ""
rowcounter = rowcounter + 1
Wend
Rows("1:1").Copy
Rows(rowcounter).Select
ActiveSheet.Paste
Selection.CutCopyMode = False

End Sub

The Excel code works. But when the ActiveX/HTML form is run again, it replaces the existing excel file. I want it to write to a pre-defined cell within the existing excel file.

Any suggestions (other than "get a webserver")? :-)

TIA, Neil.
 
Why don't you just close the file?

Then you should have the option to save changes or not.

By the way there is no SaveCopyAs method for the worksheet object.

Que?

I'm confused now...
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Neil

Did you try my suggestion of closing the file? I meant using the Close method.
 
Upvote 0
Not sure what you mean.:)
Code:
<HTML> 
<HEAD> 
<SCRIPT LANGUAGE="JavaScript"> 

<!-- Begin 
function xlWrite(r,c) { 
  var xlApp, xlSheet; 
  xlApp = new ActiveXObject("Excel.Application"); 
  xlApp.Visible = true; 
  xlApp.Workbooks.Open("C:\\xlText.xls"); 
  xlSheet = xlApp.ActiveSheet; 
  xlSheet.Cells(r,c).Value = frm.txt.value; 
  xlApp.Workbooks("xlText.xls").Close; 
  xlApp.Quit(); 
  xlApp = null; 
  setTimeout("CollectGarbage()",1); 
} 
//  End --> 
</script> 
</HEAD> 

<FORM NAME="frm"> 
  <INPUT TYPE="Text" NAME="txt" Value="Some cell text">
 
  <INPUT TYPE="Button" VALUE="Put in row 1, column 2" ONCLICK="xlWrite 
(1,1)"> 
</FORM> 


</HTML>
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,331
Members
453,032
Latest member
Pauh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top