How to delete the content of Excel cells from VBS script?

C

Claudia d'Amato

I would like to delete the current content/value of the cells

3,6 .... 3,18

How can I do this within a *.vbs script?

Claudia
 
M

Mike H

Hi,

What does '3,6 .... 3,18' mean? Are you say you want to delete all values in
the range 3.6 to 3.18?

Mike
 
H

hb21l6

Claudia d'Amato said:
I would like to delete the current content/value of the cells

3,6 .... 3,18

How can I do this within a *.vbs script?

Claudia

create a Macro in Excel.

this is a very basic example that sticks "hello in rows 2 to 20 of column A.

For i = 2 To 20

Range("A" & i).Value = "hello"

Next



Now if I wanted to blank this range, I'd just change the line to this.

Range("A" & i).Value = ""

Changing all the values to blank.
Just play about with it until you get what you want.

Dave
 
D

Dave Peterson

Does this mean Row 3, column 6 to Row 3, column 18?

And you really mean a VBS script?

If yes to both, then this worked ok for me:

================

Dim xlApp
Dim xlWks

Set xlApp = CreateObject("Excel.application")
'xlApp.Visible = True
Set xlWks = xlApp.Workbooks.Open("C:\book1.xls").Worksheets(1)

xlWks.Range("F3").Resize(1, 13).ClearContents

xlWks.Parent.Close True

xlApp.Quit

Set xlWks = Nothing
Set xlApp = Nothing

=================
It's nice to see what's happening when you're debugging. That's why I kept the
..visible line in the pasted code.
 
R

Reventlov

Il giorno 21 Jun 2008 05:07:45 GMT, (e-mail address removed) (Claudia d'Amato) ha scritto:
I would like to delete the current content/value of the cells

3,6 .... 3,18

How can I do this within a *.vbs script?

Not (totally) tested:

xl.Range(xl.Cells(3,6), xl.Cells(3,18)).ClearContents


And how to do something similar on the xls dropped on the vbs.


Set objArgs = WScript.Arguments 'Vedo se c'è almeno un argomento passato allo script
If objargs.count=0 Then 'altrimenti mostro come si usa il programma
msg= "Trascinare un file xls sull'icona del programma "
msgbox msg ,,Title
wscript.quit
End If
Filename= objArgs(0)
Set xl=CreateObject("excel.application")
xl.Visible=True
xl.Workbooks.Open Filename

FromRow=3
ToRow=3
FromColumn=6
ToColumn=18
For MyRow= fromRow to ToRow
For myColumn=fromColumn to ToColumn
cells(myRow,MyColumn)=""
next
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top