Solved

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

Posted on 2011-09-26
8
212 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
  • 4
  • 2
  • 2
8 Comments
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Is this a VSTO application?
0
 
LVL 10

Author Comment

by:Clif
Comment Utility
No.  It's old school (too many versions of MS Office to deal with from 2003 to 2010)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

Expert Comment

by:aikimark
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
That did it.

Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now