View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Richard Mueller [MVP] Richard Mueller [MVP] is offline
external usenet poster
 
Posts: 3
Default Need sample for reading value from and writing value to cell E53 from outside Excel

Tony wrote:

As fas as I heard I can write to Excel cell e.g. E53 from outside with
VBS.

How could such a code look like?

Assume I have an Excel file aaa.xls and a worksheet "ws777" inside:
How can I wread and write to this cell?


For example:
=======
Option Explicit
Dim objExcel, strExcelPath, objSheet, strValue

Set objExcel = CreateObject("Excel.Application")
strExcelPath = "c:\Scripts\aaa.xls"

' Open specified spreadsheet and select worksheet.
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets("ws777")

' Read value from cell in row 53, column E.
strValue = objSheet.Cells(53, 5).Value
Wscript.Echo strValue

' Assign value to cell in row 53, column E.
strValue = "This is a test, this is only a test."
objSheet.Cells(53, 5).Value = strValue

' Save workbook, close, and quit Excel.
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
========
I have an example VBScript program to read values from a spreadsheet linked
he

http://www.rlmueller.net/Read%20from%20Excel.htm

And another example to write value linked he

http://www.rlmueller.net/Write%20to%20Excel.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--