Do you now Object name?

A

Alexander

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?
 
J

Jean-Guy Marcil

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)?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Stefan Blom

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


--
Stefan Blom
Microsoft Word MVP


Alexander said:
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?
 
A

Alexander

"Jean-Guy Marcil" пишет:
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.
 
J

Jean-Guy Marcil

Alexander was telling us:
Alexander nous racontait que :
"Jean-Guy Marcil" ?????:


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.

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...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top