Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Word view does not change when I populate Range object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sukhi - 18 Feb 2006 11:56 GMT
Hello to good people out there!!
I am using range object and book marks to populate various parts of large
document---

           Set rBMRange = .Bookmarks("SomeValue").Range
           rBMRange.Text = strPara & vbCrLf
this works fine. but how bring parts of document being populated into view,
so user can see it happening.

When I use selection object ---
   objWord.Selection.TypeText straPara
Then I can see word moving pages where its being populating.

Could you also please explain, whats best to use, selection or range, what
are the pros and cons.  
Document I am working on is quite complicated using table and so on.  When
using selection, I can record a macro and paste into my vb project, and code
is written for me, can I do the similar thing for range object.

Thanks
Sukhi
Doug Robbins - Word MVP - 18 Feb 2006 13:07 GMT
If you really want to do it (I wouldn't), use

With ActiveDocument.Bookmarks("SomeValue").Range
   .Select
   .Text = strPara & vbCrLf
End With
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hello to good people out there!!
> I am using range object and book marks to populate various parts of large
[quoted text clipped - 19 lines]
> Thanks
> Sukhi
Helmut Weber - 18 Feb 2006 13:08 GMT
Hi Sukhi,

the behaviour you decribe is part of the very nature of ranges.
Showing on the user interface what's going on needs time.
Ranges don't do that and are therefore much faster.
Which isn't the whole truth, by far.

To list up all the differences between range and selection
seems asking for too much, IMHO.

There are a few things that work with ranges,
but not with the selection and vice versa.

I'd google for "selection" and "range",
where both words appear in the same posting.

Maybe you've noticed the short thread
"Loop to insert rows in a word table".

Try both approaches with large tables
and have a look at what's going on.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Sukhi - 18 Feb 2006 13:56 GMT
Thanks Helmut
I am beginning to enjoy working with Ranges.
Can you insert table using range, format it, populate it, and build it as I
go along.

Thats my next task

Sukhi

> Hi Sukhi,
>
[quoted text clipped - 17 lines]
> Try both approaches with large tables
> and have a look at what's going on.
Helmut Weber - 18 Feb 2006 14:34 GMT
Hi Sukhi,

yes.

Record inserting a table
and try to replace "selection" by "range"
like this:

Sub Macro14()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
rDcm.Start = rDcm.Paragraphs(2).Range.Start
rDcm.End = rDcm.Start

  ActiveDocument.Tables.Add Range:=rDcm, _
  NumRows:=4, NumColumns:= 4, _
  DefaultTableBehavior:=wdWord9TableBehavior, _
  AutoFitBehavior:= wdAutoFitFixed
  With rDcm.Tables(1)
     .Columns.PreferredWidth = InchesToPoints(0.3)
  End With
End Sub

Beware of linesbreaks by the newsreader.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 18 Feb 2006 14:51 GMT
For viewing what happened, you might consider scrollintoview:

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
ActiveDocument.Range(0, 0).Select
oRng.InsertAfter "Hello Sukhi"
ActiveWindow.ScrollIntoView oRng, True
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Sukhi,
>
[quoted text clipped - 20 lines]
>
> Beware of linesbreaks by the newsreader.
Sukhi - 18 Feb 2006 14:59 GMT
Thanks Helmut

I do the following

       .Tables.Add rBMRange, 3, 4
       rBMRange.Tables(1).Rows(1).Cells(1).Range.Text = "Value1"
       rBMRange.Tables(1).Rows(1).Cells(2).Range.Text = "Value2"
       rBMRange.Tables(1).Rows(1).Cells(3).Range.Text = "Value3"
       rBMRange.Tables(1).Rows(1).Cells(4).Range.Text = "Value14
       rBMRange.Tables(1).Rows(1).Select

first, could I have populated entrie row in one go with an arrwy? like
   rBMRange.Tables(1).Rows(1).range.text =split("Value1,Value2,..",",")

second, I want to select a row
  rBMRange.Tables(1).Rows(1).Select
then format it, shade it, change font and so on
How do i do that

Sukhi

> Hi Sukhi,
>
[quoted text clipped - 20 lines]
>
> Beware of linesbreaks by the newsreader.
Helmut Weber - 18 Feb 2006 15:20 GMT
Hi Sukhi,

like this and in many other ways,
it's just an example, nothing perfect:

Sub Macro15()
Dim t As Table
Dim aStr(1 To 4) As String
Dim lCnt As Long
Set t = ActiveDocument.Tables(1)
For lCnt = 1 To 4
  aStr(lCnt) = Format(lCnt, "0000")
Next
For lCnt = 1 To 4
  t.Cell(1, lCnt).Range.Text = aStr(lCnt)
Next
End Sub

and

Sub Macro14()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
rDcm.Tables(1).Rows(1).Shading.BackgroundPatternColorIndex = wdYellow
End Sub

Again, just the principle.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Sukhi - 18 Feb 2006 15:29 GMT
Thanks Helmut

> Hi Sukhi,
>
[quoted text clipped - 23 lines]
>
> Again, just the principle.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.