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
809 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 250 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
Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

705 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