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.

Position Curser after Picture

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michelle - 01 Feb 2006 16:16 GMT
Have VB code from a vendor that placed pictures using the
WrapFormat.Type=wdWrapTopBottom.  This is  not working as we would like so
the Type was changed to wdWrapThrough.  wdWrapNone also works for the type
but with either of these wrap styles, I cannot get the curser to be
positioned after the picture placement is done.  It remains positioned at the
top of the picture and users would need to return down past the picture to
begin typing again.  Any suggestions on vb code that would position the
curser after the picture would be greatly appreciated!  Thanks!
Jean-Guy Marcil - 02 Feb 2006 14:58 GMT
Michelle was telling us:
Michelle nous racontait que :

> Have VB code from a vendor that placed pictures using the
> WrapFormat.Type=wdWrapTopBottom.  This is  not working as we would
[quoted text clipped - 5 lines]
> on vb code that would position the curser after the picture would be
> greatly appreciated!  Thanks!

It is unclear to me why you do not want to use Top/Bottom wrapping, yet you
want that behaviour to occur in the document?

Maybe we need more info on the particulars regarding your needs?

Signature

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

Michelle - 02 Feb 2006 16:49 GMT
The picture is used in a newspaper column and when topbottom wrapping is
used, the picture is pushed into the next column.  However, if the wrapping
is changed to None or Through, the picture remains in the column it needs to
be in.  Unfortunately, changing the wrapping to None or Through would cause
problems for other ads if the curser cannot be placed immediately after the
picture when added.  Hope this additional information provides the
explanation you were looking for.  Thanks.

> Michelle was telling us:
> Michelle nous racontait que :
[quoted text clipped - 13 lines]
>
> Maybe we need more info on the particulars regarding your needs?
Jean-Guy Marcil - 02 Feb 2006 22:12 GMT
Michelle was telling us:
Michelle nous racontait que :

> The picture is used in a newspaper column and when topbottom wrapping
> is used, the picture is pushed into the next column.  However, if the
[quoted text clipped - 3 lines]
> cannot be placed immediately after the picture when added.  Hope this
> additional information provides the explanation you were looking for.

I tried with a three-column document and could not "push" the picture to the
next column.
If I placed it at the bottom of the second column, it stayed there,
regardless of the size or the surrounding paragraph attributes.

Now, since you are saying there is a macro involved that was written by a
third party, I guess you cannot post the relevant code.

My guess is that the macro is not well written and uses the Selection object
instead of the range object, so the picture does not end up where you would
expect it (There maybe other reasons, I am just guessing here....)

Signature

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

Michelle - 03 Feb 2006 18:27 GMT
Yes, I don't feel comfortable including the code since it originated from a
third party.  I'm not very experienced in VB but it seems they are using
Selection.  An example is "Selection.InlineShapes.AddPicture FileName:".  
Where the wrapping is listed, it is calling "ActiveDocument.Shapes", then
listing the WrapFormat options.  Any ideas?  Thanks.

> The picture is used in a newspaper column and when topbottom wrapping is
> used, the picture is pushed into the next column.  However, if the wrapping
[quoted text clipped - 21 lines]
> >
> > Maybe we need more info on the particulars regarding your needs?
Jean-Guy Marcil - 03 Feb 2006 19:34 GMT
Michelle was telling us:
Michelle nous racontait que :

> Yes, I don't feel comfortable including the code since it originated
> from a third party.  I'm not very experienced in VB but it seems they
> are using Selection.  An example is
> "Selection.InlineShapes.AddPicture FileName:". Where the wrapping is
> listed, it is calling "ActiveDocument.Shapes", then listing the
> WrapFormat options.  Any ideas?  Thanks.

Without seeing the code, not really.

Can you post the segment that has to do with the graphic insertion?

Signature

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

Michelle - 03 Feb 2006 20:15 GMT
Following is the segment.  Hope it is enough.  Thanks!!    
   ActiveDocument.Variables.Add ShapeName & "-W", CStr(LogoWidth)
   ActiveDocument.Variables.Add ShapeName & "-L", CStr(LogoAlign)
   ActiveDocument.Variables.Add ShapeName & "-A", AlignChoice
   ActiveDocument.Variables.Add ShapeName & "-N", LogName
   ActiveDocument.Variables.Add ShapeName & LogName
   ActiveDocument.InlineShapes(1).ConvertToShape.Name = ShapeName
   If Me.cbAttentionGetter.Value = True Then
       With ActiveDocument.Shapes(ShapeName)
           .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
           .RelativeVerticalPosition = wdRelativeVerticalPositionPage
           .Top = 1
           .LockAnchor = True
           .RelativeVerticalPosition = wdRelativeVerticalPositionPage
           .WrapFormat.Type = wdWrapTight
           .WrapFormat.Side = wdWrapRight
           .WrapFormat.DistanceLeft = 2
           .WrapFormat.DistanceRight = 2
           .WrapFormat.DistanceBottom = 0
           .WrapFormat.DistanceTop = 0
        End With
  Else
       With ActiveDocument.Shapes(ShapeName)
            .width = LogoWidth
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
            .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
            .Top = 2
            .LockAnchor = True
            .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
            .WrapFormat.Type = wdWrapTopBottom
            .WrapFormat.Side = wdWrapBoth
            .WrapFormat.DistanceBottom = 1
            .WrapFormat.DistanceTop = 1
       End With
   End If

> Michelle was telling us:
> Michelle nous racontait que :
[quoted text clipped - 9 lines]
>
> Can you post the segment that has to do with the graphic insertion?
Jean-Guy Marcil - 03 Feb 2006 20:30 GMT
Michelle was telling us:
Michelle nous racontait que :

> Following is the segment.  Hope it is enough.  Thanks!!
>    ActiveDocument.Variables.Add ShapeName & "-W", CStr(LogoWidth)
[quoted text clipped - 31 lines]
>        End With
>    End If

This code creates some document variables, then takes an inline shape (the
first one) that is already present in the document, converts it to a
floating one and then, based on some user choice from a combobox (I guess)
modifies the said shape.

I do not see any code inserting a shape..

Have I lost you somewhere along the way?

Signature

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

Michelle - 03 Feb 2006 20:44 GMT
Perhaps the following will be more helpful.  Thanks again.
Private Sub cmdInsert_Click()
   Dim AdIsScreened As Boolean
   Dim FileName As String
   Dim ShapeName As String
   Dim ShapeDescription As String
   Dim LogoWidth As Single
   Dim LogoLeftPos As Single
   Dim LogoHeight As Single
   Dim LogoPath As String
   Dim PW As Single
   Dim LM As Single
   Dim i As Integer
   Dim MoveUp As Boolean
   Dim c As Integer
   Dim char As String
   Dim MoveDown As Boolean
   Dim LogName As String
   Dim LgHeight As Single
   Dim OrgHeight As Single
   Dim NwPrcnt As Single
   Dim LogoAlign As Single
   Dim AlignChoice As String
   Dim TextExist As Boolean
   Dim EndPara As Boolean
   Dim Curserloc As Integer
   Dim FirstLine As Boolean
   Dim StartofLine As Boolean
   On Error GoTo Error_Hand:
   
   Misc.Defaults
   Misc.ReadInputFile
   Me.Hide
   FirstLine = Checks.AtStartOfDoc
If Me.cbAttentionGetter.Value = True Then
   Selection.HomeKey wdStory
End If

If Checks.AtStartOfDoc = True And check.AtEndOfDoc = True Then
   TextExist = False
   EndPara = True
Else
   TextExist = True
   Selection.EndKey wdLine
   If Asc(Selection.Text) = 13 Then
       EndPara = True
   Else
       EndPara = False
       Selection.HomeKey wdLine
   End If
   GoTo PageSetup
End If
   
PageSetup:
   PW = ActiveDocument.PageSetup.PageWidth
   LM = ActiveDocument.PageSetup.LeftMargin
   Me.Hide
   Application.ScreenUpdating = False

   
   '**********MEASUREMENTS FOR LOGO SIZES)
   If LgDefSize <> 0 Then
       LgHeight = LgDefSize * Style.Agate
   Else
       Select Case True
           Case Me.opSmll
               'LogoWidth = (PW - LM) / 2: LogoLeftPos = LM + (LogoWidth / 2)
               LogoWidth = SmallLogo
           Case Me.opMed
               'LogoWidth = (PW - LM) * 0.8: LogoLeftPos = LM + (PW - LM -
LogoWidth) / 2
               LogoWidth = MedLogo
           Case Me.opLrg
               'LogoWidth = PW - LM: LogoLeftPos = LM
               LogoWidth = LargeLogo
           Case Else
   
       End Select
   End If
   Select Case True
       Case Me.opCenter.Value
           LogoAlign = (ActiveDocument.PageSetup.PageWidth - LogoWidth) / 2
           AlignChoice = "Center"
       Case Me.opLeft.Value
           LogoAlign = Selection.ParagraphFormat.LeftIndent
           AlignChoice = "Left"
       Case Me.opRight.Value
           LogoAlign = ActiveDocument.PageSetup.PageWidth - LogoWidth
           AlignChoice = "Right"
   End Select
   If right(LogoPath, 1) <> "\" Then LogoPath = LogoPath & "\"
   LogName = Me.txtLogoPath
   If Dir(LogName) = "" Then
       MsgBox "Logo " & LogName & " does not exist"
       Me.Show
       Exit Sub
   End If
   If cbAttentionGetter.Value = True Then
       ShapeName = "SYMB-" & Fix(CDbl(Time) * 100000) + CDbl(Date) * 10 &
LogoName
   Else
       ShapeName = "LOGO-" & Fix(CDbl(Time) * 100000) + CDbl(Date) * 10 &
LogoName
   End If
   ActiveDocument.Variables.Add ShapeName, ShapeName
   DoEvents
   If Me.opLrg.Value = True Then
       ActiveDocument.Variables.Add ShapeName & "-S", "Large"
   ElseIf Me.opMed.Value = True Then
       ActiveDocument.Variables.Add ShapeName & "-S", "Medium"
   ElseIf Me.opSmll.Value = True Then
       ActiveDocument.Variables.Add ShapeName & "-S", "Small"
   Else
       ActiveDocument.Variables.Add ShapeName & "-S", "Default"
   End If
   Me.Hide
   DoEvents
   
   If Me.cbAttentionGetter.Value = False Then
       If TextExist = True Then
           If check.AtEndOfDoc = True Then
               If Checks.AtStartOfDoc = False Then
                   MoveUp = True
                   Selection.TypeParagraph
               End If
           ElseIf EndPara = False Then
               Selection.HomeKey wdLine
               StartofLine = True
           ElseIf EndPara = True Then
                Selection.MoveRight wdCharacter
           End If
       Else
           Selection.TypeParagraph
           Selection.HomeKey wdStory
           Selection.ParagraphFormat.LineSpacing = 1
       End If
   End If

   'If MoveUp = True Then
   '   Selection.MoveUp wdLine
    '  Selection.ParagraphFormat.LineSpacing = 1
   'End If
   
   Curserloc = CInt(Selection.Information(wdVerticalPositionRelativeToPage)
+ 2)
   Selection.InlineShapes.AddPicture FileName:=LogName, LinkToFile:=False,
SaveWithDocument:=True
   ActiveDocument.InlineShapes(1).Select
   ' if customer wants logos to be set line count
   ' this function figures out the percentage of change needed
   ' However, the logo's are width driven, if the depth causes the
   ' width to be to large, we force the width to the column width
   If LgDefSize <> 0 Then
       OrgHeight = Selection.InlineShapes(1).Height
       NwPrcnt = LgHeight / OrgHeight
       Selection.InlineShapes(1).LockAspectRatio = msoTrue
       LogoWidth = Selection.InlineShapes(1).width * NwPrcnt
       If LogoWidth > ActiveDocument.PageSetup.PageWidth Then
           LogoWidth = ActiveDocument.PageSetup.PageWidth - 4
       End If
   End If
  'insert variables
   ActiveDocument.Variables.Add ShapeName & "-W", CStr(LogoWidth)
   ActiveDocument.Variables.Add ShapeName & "-L", CStr(LogoAlign)
   ActiveDocument.Variables.Add ShapeName & "-A", AlignChoice
   ActiveDocument.Variables.Add ShapeName & "-N", LogName
   ActiveDocument.Variables.Add ShapeName & LogName
   ActiveDocument.InlineShapes(1).ConvertToShape.Name = ShapeName
   If Me.cbAttentionGetter.Value = True Then
       With ActiveDocument.Shapes(ShapeName)
           .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
           .RelativeVerticalPosition = wdRelativeVerticalPositionPage
           .Top = 1
           .LockAnchor = True
           .RelativeVerticalPosition = wdRelativeVerticalPositionPage
           .WrapFormat.Type = wdWrapTight
           .WrapFormat.Side = wdWrapRight
           .WrapFormat.DistanceLeft = 2
           .WrapFormat.DistanceRight = 2
           .WrapFormat.DistanceBottom = 0
           .WrapFormat.DistanceTop = 0
        End With
  Else
       With ActiveDocument.Shapes(ShapeName)
            .width = LogoWidth
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
            .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
            .Top = 2
            .LockAnchor = True
            .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
            .WrapFormat.Type = wdWrapTopBottom
            .WrapFormat.Side = wdWrapBoth
            .WrapFormat.DistanceBottom = 1
            .WrapFormat.DistanceTop = 1
       End With
   End If
   DoEvents
   ActiveDocument.Shapes(ShapeName).Select
   Selection.ShapeRange.left = LogoAlign
   LogoHeight = CStr(CSng(ActiveDocument.Shapes(ShapeName).Height))
   ActiveDocument.Variables.Add ShapeName & "-H", LogoHeight
   
   For i = 1 To ActiveDocument.Shapes.count
       If ActiveDocument.Shapes(i).Name = "Screen" Then
           AdIsScreened = True
           Exit For
       End If
   Next
   If AdIsScreened = True Then
       Application.ScreenUpdating = True
       Application.ScreenRefresh
       For i = 1 To ActiveDocument.Shapes.count
           If left(ActiveDocument.Shapes(i).Name, 4) = "LOGO" Then
                   ActiveDocument.Shapes(i).Select
                  ActiveDocument.Shapes(i).PictureFormat.Brightness = 0.41
           End If
       Next
   End If
   Application.ScreenRefresh
   Application.ScreenUpdating = True
   Selection.EndKey wdStory
   If StartofLine = False Then Selection.EndKey wdLine

   Unload Me
Exit Sub
Error_Hand:
   Dim res As Integer
   res = ErrorHandler.ErrorHandler("In procedure cmdInsert_Click of Form
frmInsertLogos", Err, DataError & ":" & ErrorMessage)
End Sub

> Michelle was telling us:
> Michelle nous racontait que :
[quoted text clipped - 43 lines]
>
> Have I lost you somewhere along the way?
Jean-Guy Marcil - 06 Feb 2006 18:18 GMT
Michelle was telling us:
Michelle nous racontait que :

> Perhaps the following will be more helpful.  Thanks again.
> Private Sub cmdInsert_Click()
[quoted text clipped - 225 lines]
> Form frmInsertLogos", Err, DataError & ":" & ErrorMessage)
> End Sub

This is too long and depends on user input, so I can't really test it.

However, I would suggest that you ask the people who wrote the macro to
remove all Selection object and use a Range object.
Also, why are they inserting an Inlinshape and then converting it to a
floating one? They could insert a floating one directly (with
ActiveDocument.Shapes.AddPicture and a defined range).

Signature

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

Michelle - 06 Feb 2006 21:35 GMT
Thanks for your time, Jean.  I will follow up with the vendor on your
questions and hopefully we can reach a resolution for this issue by making
that change.  Thanks again!

> Michelle was telling us:
> Michelle nous racontait que :
[quoted text clipped - 236 lines]
> floating one? They could insert a floating one directly (with
> ActiveDocument.Shapes.AddPicture and a defined range).
 
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.