Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Tech Eval

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 28 Dec 2004 02:53 GMT
Masters,

Earlier I posted a response in the Tables NG.  The OP was asking how to
right a macro to add 4 to the value in column A and put the result in column
B.  The OP was looking for a macro to avoid entering repetitive formulas in
his table.  I came up with the following which seems to work, but I am
wondering if it is efficient and the correct approach.  Thanks:

Sub ScratchMacro()
Dim i As Long
Dim aValue As Range
Dim bValue As Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
For i = 1 To oTbl.Rows.Count
 Set aValue = oTbl.Cell(i, 1).Range
   If IsNumeric(aValue) Then
     With aValue
       .MoveEnd Unit:=wdCharacter, Count:=-1
     End With
   Set bValue = oTbl.Cell(i, 2).Range
   bValue = aValue + 4
   End If
Next

End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Doug Robbins - Word MVP - 28 Dec 2004 06:54 GMT
Hi Greg,

I would use:

Dim i As Long, aval As Range, mytable As Table
Set mytable = Selection.Tables(1)
For i = 1 To mytable.Rows.Count
   Set aval = mytable.Cell(i, 1).Range
   aval.End = aval.End - 1
   If IsNumeric(aval) Then
       mytable.Cell(i, 2).Range.Text = aval + 4
   End If
Next i

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> Masters,
>
[quoted text clipped - 22 lines]
>
> End Sub
Greg Maxey - 28 Dec 2004 14:03 GMT
Doug,

Thanks.   I see the advantages.

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hi Greg,
>
[quoted text clipped - 41 lines]
>> Greg Maxey/Word MVP
>> A Peer in Peer to Peer Support
Jay Freedman - 28 Dec 2004 19:06 GMT
Hi Greg,

Just to be picky, you shouldn't rely on .Text being the default
property of the Range object, or on the automatic conversion of a
string to a number. It should be

   If IsNumeric(aval.Text) Then
       mytable.Cell(i, 2).Range.Text = CInt(aval.Text) + 4
   End If

or use CSng if the value in aval could have decimal places.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Doug,
>
[quoted text clipped - 45 lines]
>>> Greg Maxey/Word MVP
>>> A Peer in Peer to Peer Support
Greg Maxey - 28 Dec 2004 21:58 GMT
Jay,

Thanks.

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hi Greg,
>
[quoted text clipped - 61 lines]
>>>> Greg Maxey/Word MVP
>>>> A Peer in Peer to Peer Support
Doug Robbins - Word MVP - 28 Dec 2004 23:36 GMT
But just to be picky, if .Text isn't the default property of a .Range, what
is.  Or, perhaps the question should be "Under what circumstances might
.Text not be the default property of a range?"  If there are none, why
shouldn't you rely on the default property?

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> Hi Greg,
>
[quoted text clipped - 62 lines]
>>>> Greg Maxey/Word MVP
>>>> A Peer in Peer to Peer Support
Jay Freedman - 29 Dec 2004 04:08 GMT
>But just to be picky, if .Text isn't the default property of a .Range, what
>is.  Or, perhaps the question should be "Under what circumstances might
>.Text not be the default property of a range?"  If there are none, why
>shouldn't you rely on the default property?

Hi Doug,

Maybe "rely on" isn't the right phrase... What I had in mind is "the
whole idea of 'default property' is an abomination and shouldn't be
used". :-) The reason to use explicit properties is mainly for human
understanding. I don't want to have to remember what the default
propery is for each of a few dozen object types.

Down the road, who knows what Microsoft may pull on us? Note that
there are no default properties in C# -- a design decision that I
endorse completely.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Word Heretic - 29 Dec 2004 18:48 GMT
G'day Jay Freedman <jay.freedman@verizon.net>,

Amen. It has taught me some nasty habits I find really hard to break.
The most common one I see / use erroneously is ActiveDocument.<assumed
content story range>

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

Jay Freedman reckoned:

>Down the road, who knows what Microsoft may pull on us? Note that
>there are no default properties in C# -- a design decision that I
>endorse completely.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.