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 / September 2005

Tip: Looking for answers? Try searching our database.

Do you now Object name?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander - 31 Aug 2005 07:38 GMT
Can somebody tell name of object for multiselections?

For example: I select first and fifth word in a paragraf. How can I get it?
Selection.Words.Count give 1. Why? How can I get real number of the words?
Jean-Guy Marcil - 31 Aug 2005 17:39 GMT
Alexander was telling us:
Alexander nous racontait que :

> Can somebody tell name of object for multiselections?
>
> For example: I select first and fifth word in a paragraf. How can I
> get it? Selection.Words.Count give 1. Why? How can I get real number
> of the words?

Are you selecting only the first and fifth (2 words), or from the first to
the fifth word (five words)?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Alexander - 06 Sep 2005 07:54 GMT
> > Can somebody tell name of object for multiselections?
> >
[quoted text clipped - 4 lines]
> Are you selecting only the first and fifth (2 words), or from the first to
> the fifth word (five words)?

Yes. I select only first and fifth words. Then I want take last word in
selection.

The main task is more wide: User select some rows (for example 1st, 5th and
7th only, i.e. 3 rows) in a table, then copy it and paste. As result we must
obtain a table, but we obtain some paragraphs. I want write macros for this
operations, but don't know how get access to parts of multiselection.
Jean-Guy Marcil - 06 Sep 2005 13:58 GMT
Alexander was telling us:
Alexander nous racontait que :

> "Jean-Guy Marcil" ?????:
>
[quoted text clipped - 15 lines]
> write macros for this operations, but don't know how get access to
> parts of multiselection.

The multiselection isn't really supported in VBA. It usually only deals with
the last selection in the multiselection.

In your case, since you want to copy/paste, there is a solution. Try
something like:

'_______________________________________
Dim myRge As Range
Dim ColCount As Long

If Selection.Information(wdWithInTable) Then
   ColCount = Selection.Tables(1).Columns.Count
Else
   MsgBox "Selection must be in a table.", vbCritical, "Error"
   Exit Sub
End If

Set myRge = ActiveDocument.Range
myRge.Collapse wdCollapseEnd

Selection.Copy

myRge.Paste

myRge.ConvertToTable wdSeparateByParagraphs, , ColCount
'_______________________________________

See the ConvertToTable method in the VBA help for more info on the
parameters you can use to format the table.
Also, if you have merged cells, the results may be a bit differently from
the original selection, and so will it be different if there are paragraph
marks in the original cells...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Stefan Blom - 02 Sep 2005 11:18 GMT
One (or both) of the following KB articles may apply:

WD2002: Word Count Appears Inaccurate When You Use the VBA Words
Property
http://support.microsoft.com/default.aspx?scid=kb;en-us;291447

INFO: Limited Programmatic Access to Word 2002 Discontiguous Selections
http://support.microsoft.com/default.aspx?scid=kb;en-us;288424

Signature

Stefan Blom
Microsoft Word MVP

> Can somebody tell name of object for multiselections?
>
> For example: I select first and fifth word in a paragraf. How can I get it?
> Selection.Words.Count give 1. Why? How can I get real number of the words?
 
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.