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

Setting Formula of a Cell

30 views
Skip to first unread message

Henning Hoyer

unread,
Jan 15, 2003, 5:11:55 AM1/15/03
to

Hi all,

I'm trying to set the formula for a specific cell of a shapesheet. The code
I use is:

//Get a Shape
Set visShape = visPage.Shapes(c)

//Add a row to the Actions Section
rownum = visShape.AddRow(visSectionAction, visRowLast, 0)

//Test if our Cell exists
retval = visShape.CellsSRCExists(visSectionAction, rownum, 2, 1)

//If so go on
If (retval = -1) Then

//retrieve cell object
visCell = visShape.CellsSRC(visSectionAction, rownum, 2)

//change its formula
visCell.Formula = "HYPERLINK"
End If

As you can see, I add a new row in the Actions Section of the ShapeSheet,
which by the way works fine, and test if the specific Cell exists.
CellsSRCExists returns TRUE but the CellsSRC returns nothing!!
Since I'm a beginner with VB I'm pretty sure that I do fact overlook
something.

Thx 4 helping
Henning


Graham Wideman

unread,
Jan 21, 2003, 8:22:24 AM1/21/03
to
Henning

First, if you are going to detect true/false using integers, it would be a
good idea to test against zero rather than a specific non-zero value, as
there are some functions that look like they should return -1 but actually
return 1.

Ie: instead of

if retval = -1 then

better:

if retval <> 0 then

Next, if your code should have just created the row in question, then you
shouldn't need to test for exist. But it is usually good to check that an
object reference is actually not nothing, so might as well take care of both
at once. And when I went to write this example I saw your mistake -- fooled
again by the evil lack-of-Set pitfall!

//Add a row to the Actions Section
rownum = visShape.AddRow(visSectionAction, visRowLast, 0)

On Error Resume Next
Set visCell = visShape.CellsSRC(visSectionAction, rownum, 2)
if not (visCell is Nothing) then

visCell.Formula = "HYPERLINK"

Graham
--
---------------------------------------------------
Graham Wideman
Microsoft Visio MVP
---------------------------------------------------
Book/Tools:
Visio 2002 Developer's Survival Pack
Resources for programmable diagramming at:
http://www.diagramantics.com
grah...@diagramantics.com
.

"Henning Hoyer" <hennin...@khe.siemens.de> wrote in message
news:10426255...@baruth.khe.siemens.de...

Roger Cuadras

unread,
Feb 3, 2003, 7:01:59 AM2/3/03
to

Hello, Henning.

Did Graham suggestion work ? I'm doing things similar to
what you do.

Related to your line code:

visCell.Formula = "HYPERLINK"

have you tried:

visCell.Formula = variable_name

where variable_name would be a String variable
containing "HYPERLINK" ? I'm experiencing problems there,
changing the contents of a cell from a variable, my code
is slightly different from your one, row is created, type
is 0 (String), but I do not get the cell updated from the
contents of a variable.

Kind regards,

Roger

>.
>

Jeff[MS]

unread,
Feb 5, 2003, 1:45:32 AM2/5/03
to
Roger

Try triple quoting the string, as in:

visCell.Formula = """HYPERLINK"""

That should work


"Roger Cuadras" <rcua...@telefonica.net> wrote in message
news:02b101c2cb7c$0e08dbc0$8df82ecf@TK2MSFTNGXA02...

0 new messages