Group: microsoft.public.word.vba.general
From: melon
Date: Thursday, February 21, 2008 2:53 PM
Subject: Re: Inserting a checkbox using VBA

On Feb 21, 3:19 pm, Jean-Guy Marcil
wrote:
> "melon" wrote:
> > Thanks, I tried to switch every selection into range then it seems to
> > work.
>
> > But after inserting one checkbox, how do I insert another with a new
> > line? I try to use Range.InsertAfter vbNewLine or
> > Range.InsertParagraph in between each checkbox but that doesn't work.
>
> Hre is an example of what you can do. I have moved the Checkbox stuff in a
> function so that it can be called as oftewn as you need, in this case, 3
> times.
>
> Sub ManageCheck()
>
> Dim i As Long
> Dim rgeTarget As Range
>
> Set rgeTarget = ActiveDocument.Range.Paragraphs(2).Range
> rgeTarget.InsertParagraphAfter
>
> For i = 1 To 3
> rgeInsertCheck rgeTarget, i
> Next
>
> End Sub
>
> Function rgeInsertCheck(ByRef rgeInsert As Range, ByVal lngCount As Long) As
> Range
>
> Dim inShpCheck As InlineShape
>
> With rgeInsert
> .Collapse wdCollapseEnd
> Set inShpCheck = .InlineShapes.AddOLEControl("Forms.CheckBox.1",
> rgeInsert)
> .MoveEnd wdCharacter, 1
> .Collapse wdCollapseEnd
> .InsertParagraphAfter
> .InsertParagraphAfter
> End With
>
> With inShpCheck.OLEFormat.Object
> .Caption = "Names" & lngCount
> End With
>
> End Function

I don't know what's going on but the new checkbox control will still
get inserted in the same line. The InsertParagraph will execute first
(even if it is placed after InlineShapes.AddOLEContro), then the
control box is drawn in a horizontal arrangement.

Safety Articles | Usenet Groups | Usenet News | Bluegrass