Solved

Automating Word: Assigning a Range of Cells to a Range Object

Posted on 2011-09-26
8
219 Views
Last Modified: 2012-05-12
I should know this.  I even feel like I've asked before, but can't find it my previous questions.

I have a Word table I created through VB.Net.  The table is 10 columns by 20 rows.  I need to modify the first six columns of the first three rows.

To that end, I'm hoping to do something like this:
(Note: Even though it looks like Excel, it's a Word table)
Dim oRange As Object = oTable.Cells("A1", "F3")

Obvoiusly that doesn't work or I wouldn't be posting here.

How do I do this?

TIA

0
Comment
Question by:Clif
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 36708504
Long time since I worked with the Word object model, but this seems to do the trick (In the ThisDocument code module):

Public Sub TryIt()
Dim t As Table
Set t = Me.Tables(1)
Dim r As Range
Set r = Me.Range(Start:=t.Cell(2, 3).Range.Start, End:=t.Cell(4, 5).Range.End)
r.Select
End Sub
0
 
LVL 10

Author Comment

by:Clif
ID: 36709199
I'm having problems with the "Me" part of your example.  It doesn't make sense to me, and I have no idea how to convert it to something that does.

Perhaps I wasn't clear enough in my OP.  I'm using VB.Net 2010 Professional.  I'm not doing this within Word's Macro code.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 36709675
Is this a VSTO application?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Clif
ID: 36709751
No.  It's old school (too many versions of MS Office to deal with from 2003 to 2010)
0
 
LVL 45

Expert Comment

by:aikimark
ID: 36709788
>>It's old school

So, is it a VB classic application or a VB.Net application? -- just how 'old' is this school?
0
 
LVL 10

Author Comment

by:Clif
ID: 36710014
It is a VB.Net (2010 Professional) application creating a Word document for machines with Word 2003, 2007, or 2010 installed.  Because of variety of versions or Word I am to support, my app is using late binding.
0
 
LVL 27

Assisted Solution

by:MikeToole
MikeToole earned 500 total points
ID: 36710203
The 'Me' prefix refers to the Document instance when used in the ThisDocument class in either vba or vsto.
Replace it with a reference to your document instance.
0
 
LVL 10

Author Closing Comment

by:Clif
ID: 36710520
That did it.

Thanks
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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