Log in

View Full Version : Solved: Automatically Insert Picture as InLine



Paul_Hossler
01-31-2010, 01:30 PM
Is there a way to always insert a picture with Text Wrap = Inline?

I tried to write my own InsertPicture so that it would be called instead of the built in one, but never got anything close to working

It's easy enough to do the pieces, but the challenge seems to be making it seamless: calling my InsertPicture instead of Word's and setting it to InLine.

Paul

macropod
01-31-2010, 11:51 PM
Hi Paul,

The better approach, IMHO, would be to use Word's InsertPicture dialogue box & process, then simply convert the inserted picture (which the insertion leaves selected) to whichever non-'in line' format you require.

Paul_Hossler
02-01-2010, 09:47 AM
my bad - I meant that I wanted the inserted picture to automatically have Text Wrapping = Square. It always comes up InLine

Yes, I can do it in two steps, but I thought that since for me the most common case (by far) is to Text Wrap = Square and apply some formating, it'd be easier to only have to change the 'once in awhile' case to InLine

This is what I have so far. There's some formatting that I'll add, but I can't get Word to call my InsertPicture ... It keeps wanting to all it's own


Sub InsertPicture()
Dim oDialog As Dialog

Set oDialog = Application.Dialogs(wdDialogInsertPicture)


With oDialog

If .Show = 0 Then Exit Sub

End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

Selection.ChildShapeRange.WrapFormat.Type = wdWrapSquare
End Sub


Paul

fumei
02-01-2010, 10:01 AM
" There's some formatting that I'll add, but I can't get Word to call my InsertPicture ... It keeps wanting to all it's own"

Where do you have the Sub InsertPicture? Because it should be firing yours.

Paul_Hossler
02-01-2010, 10:25 AM
In my .docm

fumei
02-01-2010, 10:47 AM
I refuse to use 2007, so I can not really look at this. Perhaps there is something about 2007 docm files that does NOT override internal procedures by writing a new one.

I do know that:
Sub InsertPicture()
Msgbox "You just tried to insert a picture...sorry...no."
End Sub
does override the internal Sub InsertPicture from any valid code module, in versions up to 2003. Maybe Tony can help you.

Paul_Hossler
02-01-2010, 02:19 PM
Hi -- thanks

That's the way I remember it working in the good old 2003 days

I tried my 2007 code by backsaving in 97/2003 format, but the VBA is not backwards compatible.

But, that still does not explain why I can't overlay an internal command.

More Googling I guess

Paul

fumei
02-01-2010, 03:20 PM
Do re-post if you find an answer.

macropod
02-02-2010, 01:06 AM
Hi Paul,

The following code should intercept the in Word 2007 (it does in earlier versions) but, for whatever reason, it doesn't. It works in earlier versions and makes the insertion of pictures as 'square'-formatted shapes a snap.

Sub InsertPicture()
With Selection
If Application.Dialogs(wdDialogInsertPicture).Show = 0 Then Exit Sub
.MoveLeft wdCharacter, 1, True
If .Type = wdSelectionInlineShape Then .InlineShapes(1).ConvertToShape
End With
End Sub

Paul_Hossler
02-02-2010, 10:33 AM
Mac

I thought it would work also. I also tried PictureInsertFromFile, which is the Ribbon control ID, but still did not work

I like your code more than mine so i'll use your's

Thanks

Paul

macropod
02-02-2010, 01:29 PM
Hi Paul,

For Word 2007, you can go to Word Options|Advanced > Cut Copy & Paste > Insert/paste pictures as: Square.

This gives you the option of using Document_Open and Document_Close events to toggle the mode for individual documents. For example:

Option Explicit
Dim InsPaste

Private Sub Document_Open()
InsPaste = Options.PictureWrapType
Options.PictureWrapType = wdWrapMergeSquare
End Sub

Private Sub Document_Close()
Options.PictureWrapType = InsPaste
End Sub

Paul_Hossler
02-02-2010, 01:46 PM
Even better

Thanks

Paul