From: andreas on
Dear experts:

I wonder whether the following is possible

I got five text entries, each in its own paragraph

text1
text2
text3
text4
text5

With all 5 paragraphs selected is it possible to create 5 five
bookmarks automatically via VBA with the following names:

text1 (bookmark name: product_de)
text2 (bookmark name: product_en)
text3 (bookmark name: product_es)
text4 (bookmark name: product_fr)
text5 (bookmark name: product_it)

I hope this is feasible and not beyond the scope of this forum.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
From: macropod on
Hi andreas,

You could use code like:
Sub Demo()
Dim StrBkMk As String, i, x As Integer
StrBkMk = "product_de,product_en,product_es,product_fr,product_it"
x = 5
With Selection
If .Paragraphs.Count < 5 Then x = .Paragraphs.Count
For i = 1 To x
.Paragraphs(i).Range.Bookmarks.Add (Split(StrBkMk, ",")(i - 1))
Next
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


"andreas" <andreas.hermle(a)gmx.de> wrote in message news:6f22bcf7-3972-4c0e-b8e3-4322dece4be5(a)u22g2000yqf.googlegroups.com...
> Dear experts:
>
> I wonder whether the following is possible
>
> I got five text entries, each in its own paragraph
>
> text1
> text2
> text3
> text4
> text5
>
> With all 5 paragraphs selected is it possible to create 5 five
> bookmarks automatically via VBA with the following names:
>
> text1 (bookmark name: product_de)
> text2 (bookmark name: product_en)
> text3 (bookmark name: product_es)
> text4 (bookmark name: product_fr)
> text5 (bookmark name: product_it)
>
> I hope this is feasible and not beyond the scope of this forum.
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas
From: Doug Robbins - Word MVP on
The following code will do it:

Dim i As Long
Dim bmnames As Variant
bmnames = Split("product_de,product_en,product_es,product_fr,product_it",
",")
With Selection.Range
If .Paragraphs.Count = 5 Then
For i = 1 To .Paragraphs.Count
ActiveDocument.Bookmarks.Add bmnames(i - 1),
..Paragraphs(i).Range
Next i
Else
MsgBox "Please select only five paragraphs."
End If
End With


--
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, originally posted via msnews.microsoft.com

"andreas" <andreas.hermle(a)gmx.de> wrote in message
news:6f22bcf7-3972-4c0e-b8e3-4322dece4be5(a)u22g2000yqf.googlegroups.com...
> Dear experts:
>
> I wonder whether the following is possible
>
> I got five text entries, each in its own paragraph
>
> text1
> text2
> text3
> text4
> text5
>
> With all 5 paragraphs selected is it possible to create 5 five
> bookmarks automatically via VBA with the following names:
>
> text1 (bookmark name: product_de)
> text2 (bookmark name: product_en)
> text3 (bookmark name: product_es)
> text4 (bookmark name: product_fr)
> text5 (bookmark name: product_it)
>
> I hope this is feasible and not beyond the scope of this forum.
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas

From: andreas on
On Apr 5, 11:24 am, "Doug Robbins - Word MVP"
<d...(a)REMOVECAPSmvps.org> wrote:
> The following code will do it:
>
> Dim i As Long
> Dim bmnames As Variant
> bmnames = Split("product_de,product_en,product_es,product_fr,product_it",
> ",")
> With Selection.Range
>     If .Paragraphs.Count = 5 Then
>         For i = 1 To .Paragraphs.Count
>             ActiveDocument.Bookmarks.Add bmnames(i - 1),
> .Paragraphs(i).Range
>         Next i
>     Else
>         MsgBox "Please select only five paragraphs."
>     End If
> End With
>
> --
> 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, originally posted via msnews.microsoft.com
>
> "andreas" <andreas.her...(a)gmx.de> wrote in message
>
> news:6f22bcf7-3972-4c0e-b8e3-4322dece4be5(a)u22g2000yqf.googlegroups.com...
>
>
>
> > Dear experts:
>
> > I wonder whether the following is possible
>
> > I got five text entries, each in its own paragraph
>
> > text1
> > text2
> > text3
> > text4
> > text5
>
> > With all 5 paragraphs selected is it possible to create 5 five
> > bookmarks automatically via VBA with the following names:
>
> > text1 (bookmark name: product_de)
> > text2 (bookmark name: product_en)
> > text3 (bookmark name: product_es)
> > text4 (bookmark name: product_fr)
> > text5 (bookmark name: product_it)
>
> > I hope this is feasible and not beyond  the scope of this forum.
>
> > Help is much appreciated. Thank you very much in advance.
>
> > Regards, Andreas- Hide quoted text -
>
> - Show quoted text -

Hi Macropod and Doug,

thank you very much for your great help. Both code work almost as
desired. Is it possible to exclude the paragraph marks in the
selection?

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
From: Doug Robbins - Word MVP on
Use:

Dim i As Long
Dim bmnames As Variant
Dim target As Range
bmnames = Split("product_de,product_en,product_es,product_fr,product_it",
",")
With Selection.Range
If .Paragraphs.Count = 5 Then
For i = 1 To .Paragraphs.Count
Set target = .Paragraphs(i).Range
target.End = target.End - 1
ActiveDocument.Bookmarks.Add bmnames(i - 1), target
Next i
Else
MsgBox "Please select only five paragraphs."
End If
End With


--
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, originally posted via msnews.microsoft.com

"andreas" <andreas.hermle(a)gmx.de> wrote in message
news:be0b4cfb-7823-4762-a720-0cc7bb48a5f1(a)j21g2000yqh.googlegroups.com...
> On Apr 5, 11:24 am, "Doug Robbins - Word MVP"
> <d...(a)REMOVECAPSmvps.org> wrote:
>> The following code will do it:
>>
>> Dim i As Long
>> Dim bmnames As Variant
>> bmnames = Split("product_de,product_en,product_es,product_fr,product_it",
>> ",")
>> With Selection.Range
>> If .Paragraphs.Count = 5 Then
>> For i = 1 To .Paragraphs.Count
>> ActiveDocument.Bookmarks.Add bmnames(i - 1),
>> .Paragraphs(i).Range
>> Next i
>> Else
>> MsgBox "Please select only five paragraphs."
>> End If
>> End With
>>
>> --
>> 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, originally posted via msnews.microsoft.com
>>
>> "andreas" <andreas.her...(a)gmx.de> wrote in message
>>
>> news:6f22bcf7-3972-4c0e-b8e3-4322dece4be5(a)u22g2000yqf.googlegroups.com...
>>
>>
>>
>> > Dear experts:
>>
>> > I wonder whether the following is possible
>>
>> > I got five text entries, each in its own paragraph
>>
>> > text1
>> > text2
>> > text3
>> > text4
>> > text5
>>
>> > With all 5 paragraphs selected is it possible to create 5 five
>> > bookmarks automatically via VBA with the following names:
>>
>> > text1 (bookmark name: product_de)
>> > text2 (bookmark name: product_en)
>> > text3 (bookmark name: product_es)
>> > text4 (bookmark name: product_fr)
>> > text5 (bookmark name: product_it)
>>
>> > I hope this is feasible and not beyond the scope of this forum.
>>
>> > Help is much appreciated. Thank you very much in advance.
>>
>> > Regards, Andreas- Hide quoted text -
>>
>> - Show quoted text -
>
> Hi Macropod and Doug,
>
> thank you very much for your great help. Both code work almost as
> desired. Is it possible to exclude the paragraph marks in the
> selection?
>
> Help is much appreciated. Thank you very much in advance. Regards,
> Andreas