?
Solved

Word Macro  that will move the cursor to the 2nd Cell in the 3rd Table in the Active Word Document

Posted on 2009-04-11
7
Medium Priority
?
813 Views
Last Modified: 2012-06-21
I need help writing a Macro that will move the cursor to the 2nd Cell in the 3rd Table in the Active Word Document.
0
Comment
Question by:FaheemAhmadGul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1000 total points
ID: 24122128
Hello FaheemAhmadGul,

Word VBA doesn't let you move in that way, you have to step through the docuemnt.  You can howeever read / write diresctly:

Write:
    thisdocument.Tables(3).Cell(1,1).Range.Text = "Fred"
Read:
    thisdocument.Tables(3).Cell(1,1).Range.Text

Note however it is cell(row, column) rather than cell(x)

Regards,
Chris
0
 
LVL 1

Author Comment

by:FaheemAhmadGul
ID: 24122249
I have been able to use the code provided by you to get my cursor where I wanted it to be. This is by first writing to the Cell  I want the Cursor to go to, then taking the cursor to that cell by searching for that word.

Many thanks for your help. I am grateful.
Regards
Faheem
Private Sub btnCellThree_Click()
 
ThisDocument.Tables(3).Cell(1, 2).Range.Text = "Fred"
 
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "Fred"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
     
    End With
    Selection.Find.Execute
    Selection.Delete Unit:=wdCharacter, Count:=1
  
    Selection.TypeText Text:="This has worked."
   
    
  
 
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:FaheemAhmadGul
ID: 31569168
have been able to use the code provided by you to get my cursor where I wanted it to be. This is by first writing to the Cell  I want the Cursor to go to, then taking the cursor to that cell by searching for that word.

Many thanks for your help. I am grateful.
Regards
Faheem
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24122280
NOw that is sneaky! ... but clever.  Personally I would have set a bookmark but your way is perhaps even simpler so thank you for the advice.

I didn't define such possibilities as I was assuming the need was to type something there or read the value.  I would of course have taken it further had that been the requirement - but I am pleased you did so for yourself.

Chris
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 24122475
I should have done it in your previous question, but it isn't too difficult:
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 24122477
This the code that I meant to include with the previous comment
Sub MoveTocell()
 ActiveDocument.Tables(3).Cell(2, 2).Range.Select
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:FaheemAhmadGul
ID: 24122684
This is brilliant !  Accomplishes what I wish to do in a much simpler way. I actually wanted to be able to take the cursor to a specific cell in a specific table in my document and run a number of other macros and commands when the cursor was there. This one line of code, very kindly provided you, solves the problem.
I am very grateful. Thank you very much.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question