A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Apply a macro to a specified Cell



 
 
Thread Tools Display Modes
  #1  
Old October 21st, 2005, 06:18 PM
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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.

  #2  
Old October 21st, 2005, 07:53 PM
Greg
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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

  #3  
Old October 24th, 2005, 04:21 PM
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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

  #4  
Old October 25th, 2005, 01:59 PM
Greg
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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

  #5  
Old October 26th, 2005, 03:12 PM
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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?

  #6  
Old October 26th, 2005, 03:20 PM
Greg
external usenet poster
 
Posts: n/a
Default Apply a macro to a specified Cell

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro help - copy a cell down gjcase General Discussion 3 September 4th, 2005 05:09 AM
move to another cell within a subtotal report within a macro NoelH Worksheet Functions 1 August 31st, 2005 03:02 PM
Relative Cell position NOT working with or without macro Scratching my Head General Discussion 6 May 30th, 2005 06:12 PM
IF E3 & E10 = TRUE set this cell to "Yes", else set to "No" Timothy L Worksheet Functions 5 August 27th, 2004 02:28 AM
Can A Macro "Add" Content To A Cell Without Replacing The Original Content? Minitman Worksheet Functions 3 March 25th, 2004 01:06 AM


All times are GMT +1. The time now is 02:16 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.