Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how can i use vbscript to modify an already opend excel file?

380 views
Skip to first unread message

sichuan...@gmail.com

unread,
Dec 15, 2007, 11:59:04 AM12/15/07
to
I have already open a excel file "d:\test.xls"

then I want to use vbscript to modify this file by not closing it and
then open it.

How should this script written?

thanks.

Paul Randall

unread,
Dec 15, 2007, 1:07:57 PM12/15/07
to

<sichuan...@gmail.com> wrote in message
news:246ef526-0d5a-4ffb...@i29g2000prf.googlegroups.com...

I don't quite understand what you want to do. This is a VBScript
newsgroup. VBScript can not directly open an Excel spreadsheet file
and display its contents in a meaningful way (at least not without a
lot of script). So maybe you are talking about having opened the file
from Microsoft Excel or some other Excel spreadsheet viewer. Maybe
you are talking about having run an Excel macro (VBA) to open the
file, and you need to go to a VBA newsgroup for help.

I'm thinking your intent is to view the file in one window and then
have another application change the file and see if the first window
can see the changes, but that is just a wild guess.

Try to explain better what you want to do, and whether you have Excel
installed on your computer, and whether you want to do it in Excel's
VBA or VBScript.

-Paul Randall


sichuan...@gmail.com

unread,
Dec 16, 2007, 3:24:47 AM12/16/07
to
On Dec 16, 2:07 am, "Paul Randall" <paulr...@cableone.net> wrote:
> <sichuan.mob...@gmail.com> wrote in message

Thanks for your writing. I will explain it more clearly.

I have opened several files ( e.g d:\test.xls , d:\a.xls and so
on ) from Microsoft Excel.
And I want to view a d:\test.xls in one window and then
have another application(use VBScript) to change the file and see if


the first window
can see the changes,

Regards.

Paul Randall

unread,
Dec 16, 2007, 1:40:58 PM12/16/07
to

<sichuan...@gmail.com> wrote in message
news:44d79fe3-42c4-4db4...@e6g2000prf.googlegroups.com...

When you open file d:\test.xls in Excel, it is typically opened with
read and write access. I suppose it is possible to open a file with
read access only, but I don't know how to do this in Excel. As you
can imagine, there would be chaos if a file were simultaneously opened
with more than one application with write access to the file, unless
some other means is used to coordinate the access. The operating
system typically locks file to prevent more than one application
having write access to that file at the same time. With the proper
software, some files can be locked at the record level. In any case,
after Excel has opened the file and displayed its contents, Excel
typically does not read the file again periodically and thus does not
display any changes that might have occurred.

Some software packages behave differently. For example, the free
version of PSPad text editor does not lock the file when you open it
in the editor. So, for example, if your script writes a log file, you
can have that log file open in PSPad. When you give PSPad focus, it
checks whether the files in any of its tabs have changed, and gives
you the oportunity to reload the changed file or continue displaying
the previous contents.

-Paul Randall


ekkehard.horner

unread,
Dec 16, 2007, 2:05:15 PM12/16/07
to
sichuan...@gmail.com schrieb:

> On Dec 16, 2:07 am, "Paul Randall" <paulr...@cableone.net> wrote:
>> <sichuan.mob...@gmail.com> wrote in message
>>
>> news:246ef526-0d5a-4ffb...@i29g2000prf.googlegroups.com...
>>
>>> I have already open a excel file "d:\test.xls"
>>> then I want to use vbscript to modify this file by not closing it
>>> and
>>> then open it.
>>> How should this script written?
>> I don't quite understand what you want to do. This is a VBScript
>> newsgroup. VBScript can not directly open an Excel spreadsheet file
>> and display its contents in a meaningful way (at least not without a
>> lot of script).
[...]

>> -Paul Randall
>
> Thanks for your writing. I will explain it more clearly.
>
> I have opened several files ( e.g d:\test.xls , d:\a.xls and so
> on ) from Microsoft Excel.
> And I want to view a d:\test.xls in one window and then
> have another application(use VBScript) to change the file and see if
> the first window
> can see the changes,
[...]

As Paul told you, you can't use VBScript/FileSystemObject to access
a file opened in Excel; you can't even read an unused .xls, because
VBScript/FileSystemObject can't work with binary files.

You can use Excel from VBScript via COM/Create|GetObject( "Excel.Application")
and make it do something which could be done by a user or an Excel *VBA*
Macro/Program. But in your user centric/interactive scenario, you wouldn't
gain anything from using VBScript. It would be much easier to do what you want
in VBA (and to ask for details in an Excel newsgroup).

(Sorry to be so destructive)

0 new messages