Hello

We generate word documents from content in a database (AuthorIT
application). I want to have an image on the front page of my document
_behind_ the text. When generated, the text is wrapped around the image. I
want to use a macro to set the image to display beneath the text.

I have come up with this macro:

Sub MoveImage()
Dim iShape, Shape
On Error Resume Next
For Each iShape In ActiveDocument.Sections.First.Range.InlineShapes
iShape.ConvertToShape
Next
For Each Shape In ActiveDocument.Sections.First.Range.ShapeRange
Shape.WrapFormat.Type = wdWrapThrough
Next
End Sub

This doesn't work when run as soon as the doc is generated, but curiously
does work if i manually select the image then run it.

Can anyone help me to develop a macro that will set the desired wrapping
without any manual action?

Thanks

Dave.

RE: Controlling text wrapping around an image. by davidalexsmith

davidalexsmith
Thu Aug 18 05:56:03 CDT 2005

I should also mention that the image is output in my own-defined style. So if
it's possible to have images in a particular style sit beneath the text, this
would be a good solution.

Any ideas?

"david_alex_smith" wrote:

> Hello
>
> We generate word documents from content in a database (AuthorIT
> application). I want to have an image on the front page of my document
> _behind_ the text. When generated, the text is wrapped around the image. I
> want to use a macro to set the image to display beneath the text.
>
> I have come up with this macro:
>
> Sub MoveImage()
> Dim iShape, Shape
> On Error Resume Next
> For Each iShape In ActiveDocument.Sections.First.Range.InlineShapes
> iShape.ConvertToShape
> Next
> For Each Shape In ActiveDocument.Sections.First.Range.ShapeRange
> Shape.WrapFormat.Type = wdWrapThrough
> Next
> End Sub
>
> This doesn't work when run as soon as the doc is generated, but curiously
> does work if i manually select the image then run it.
>
> Can anyone help me to develop a macro that will set the desired wrapping
> without any manual action?
>
> Thanks
>
> Dave.

RE: Controlling text wrapping around an image. by HelmutWeber

HelmutWeber
Thu Aug 18 07:49:30 CDT 2005

Hi David,

I don't know, but this works for me:

Dim oShp As Shape
For Each oShp In ActiveDocument.Range.ShapeRange
oShp.WrapFormat.Type = wdWrapNone ' 3 !
Next

And your variable definitions are far from perfect.
Also, "on error" seems to be useless here.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000



RE: Controlling text wrapping around an image. by HelmutWeber

HelmutWeber
Thu Aug 18 07:58:30 CDT 2005

...
same applies to
oShp.WrapFormat.Type = wdWrapThrough
of course.

Helmut Weber


RE: Controlling text wrapping around an image. by davidalexsmith

davidalexsmith
Thu Aug 18 08:12:06 CDT 2005

Helmut,

Thanks, but I get:

"Requested object is not available" when i run this.

Dave.

"Helmut Weber" wrote:

> ...
> same applies to
> oShp.WrapFormat.Type = wdWrapThrough
> of course.
>
> Helmut Weber
>

RE: Controlling text wrapping around an image. by davidalexsmith

davidalexsmith
Thu Aug 18 08:23:01 CDT 2005

It seems like the image is inserted as an inlineshape.

This works:

Sub MoveImage()
Dim oShp As Shape
Dim iShape As InlineShape
For Each iShape In ActiveDocument.Sections.First.Range.InlineShapes
iShape.ConvertToShape
Next
For Each oShp In ActiveDocument.Shapes
oShp.WrapFormat.Type = wdWrapThrough
Next
End Sub

BUT ONLY if the image is selected in the doc. Any ideas on how to make it
work regardless? Shall i attempt to select the image programatically first?

"david_alex_smith" wrote:

> Helmut,
>
> Thanks, but I get:
>
> "Requested object is not available" when i run this.
>
> Dave.
>
> "Helmut Weber" wrote:
>
> > ...
> > same applies to
> > oShp.WrapFormat.Type = wdWrapThrough
> > of course.
> >
> > Helmut Weber
> >

RE: Controlling text wrapping around an image. by HelmutWeber

HelmutWeber
Thu Aug 18 08:32:11 CDT 2005

Hi David,

I simplified the code a bit, reduced it to the essentials.
And thought, you could adapt it without problems.

Well, a more explicit piece of code could look like this:

' ---
Dim oInlSh As InlineShape ' Object Inlineshape
Dim oShape As Shape ' Object Shape

For Each oInlSh In ActiveDocument.Range.InlineShapes
oInlSh.ConvertToShape
Next
For Each oShape In ActiveDocument.Range.ShapeRange
oShape.WrapFormat.Type = wdWrapThrough
Next
' ---
If You want to adress sections,
you have to add the appropriate code pieces again.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000



RE: Controlling text wrapping around an image. by HelmutWeber

HelmutWeber
Thu Aug 18 08:36:02 CDT 2005

Hi David,

hard to say anything more,

as the code I just pasted from your posting,
works perfectly here and now without any alterations.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000



RE: Controlling text wrapping around an image. by davidalexsmith

davidalexsmith
Thu Aug 18 08:50:05 CDT 2005

OK Helmut, thanks for your efforts anyway. (Sorry I'm only an amateur)

It's strange. The ConvertToShape method fails unless I first select the
image. I might try and find a totally different solution.

"Helmut Weber" wrote:

> Hi David,
>
> hard to say anything more,
>
> as the code I just pasted from your posting,
> works perfectly here and now without any alterations.
>
> Greetings from Bavaria, Germany
> Helmut Weber, MVP WordVBA
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
>
>