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 / Tables / October 2005

Tip: Looking for answers? Try searching our database.

Apply a macro to a specified Cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abelp1975@hotmail.com - 21 Oct 2005 18:18 GMT
Dear PEOPLE:

I need to apply a macro to a specified Cell in my table.
My table is 2x2 and I want that macro applied to that cell ONLY.
My cell is located at Cell(2,1) [row, column].

Can any one help me?

Thank you.
Abel.
Greg - 21 Oct 2005 19:53 GMT
Dear Abel,

An example:

Sub Test()
Dim oTable As Table
Set oTable = ActiveDocument.Tables(1) 'first table in document

With oTable.Cell(2, 1).Range
  .Text = "Bobs your uncle"
  .Font.Color = wdColorBlue
  .Borders.OutsideLineStyle = wdLineStyleDouble
End With
End Sub
abelp1975@hotmail.com - 24 Oct 2005 16:21 GMT
Thank you Greg.
The macro works perfect but I have severall actions to insert in
bettewn the "With oTable" and the "End With": various find and replaces
all diferent. Could you explain me how to do that?

Thanks
Abel
Greg - 25 Oct 2005 13:59 GMT
Abel,

If you are doing a find/replace then set the range to the table cell.

Sub Test()
Dim myRng As Range
Set myRng = ActiveDocument.Tables(1).Cell(2, 1).Range
With myRng.Find
 .Text = "uncle"
 .Replacement.Text = "favorit uncle"
 .Execute Replace:=wdReplaceAll
End With
End Su
abelp1975@hotmail.com - 26 Oct 2005 15:12 GMT
Dear Greg
Thank you once again.
I'm doing several find/replacements you thing this could be done
correctly like this:

Sub Test()
Dim myRng As Range
Set myRng = ActiveDocument.Tables(1).Cell(2, 1).Range
With myRng.Find
 .Text = "uncle"
 .Replacement.Text = "favorit uncle"
 .Text = "nefew"
 .Replacement.Text = "favorit nefew"
 .Text = "sista"
 .Replacement.Text = "favorit sista"
 .Execute Replace:=wdReplaceAll
End With
End Sub

I mean several replacements inside the same with/range action?
Greg - 26 Oct 2005 15:20 GMT
Abel,

Did you try it?  What do you think?

I don't think so, because before the .Execute statement you have only
changed your mind twice regarding what text you want to find and what
you want that text replaced with.

This would work:

Sub Test1()
Dim myRng As Range
Set myRng = ActiveDocument.Tables(1).Cell(2, 1).Range
With myRng.Find
 .Text = "uncle"
 .Replacement.Text = "favorit uncle"
 .Execute Replace:=wdReplaceAll
 .Text = "nefew"
 .Replacement.Text = "favorit nefew"
 .Execute Replace:=wdReplaceAll
 .Text = "sista"
 .Replacement.Text = "favorit sista"
 .Execute Replace:=wdReplaceAll
End With
End Sub
 
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.