Word

Insert Picture from Picture dialog

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

MOS MASTER

Description:

One sub will insert a picture as InlineShape (threated as range) in the active document. The other sub will insert a picture as Shape (Floating) in the active document. Both subs write the pictures to the selection 

Discussion:

A quick method to insert a picture through the picture dialog. Sometimes you want an Inlinepicture and sometimes you want to insert a Shape instead that you can move around (Drag and Drop) With the Shape sub you can specify: Left, Top, Width and Height to position the Shape. 

Code:

instructions for use

			

Option Explicit ' \\ This sub inserts a Inline Picture to the selection Sub InsertInlinePictureDialog() Dim oDialog As Word.Dialog ' \\ Get a handle to the Insert picture dialog Set oDialog = Dialogs(wdDialogInsertPicture) ' \\ Work with dialog With oDialog ' \\ Display the dialog .Display ' \\Insert InlineShape if the Name property (Filepath) <> "" If .Name <> "" Then ActiveDocument.InlineShapes.AddPicture FileName:=.Name, _ LinkToFile:=False, _ SaveWithDocument:=True, _ Range:=Selection.Range End If End With ' \\ Clean up Set oDialog = Nothing End Sub ' \\ This sub inserts a Shape (Flowting) Picture to the selection Sub InsertFlowtingPictureDialog() Dim oDialog As Word.Dialog ' \\ Get a handle to the Insert picture dialog Set oDialog = Dialogs(wdDialogInsertPicture) ' \\ Work with dialog With oDialog ' \\ Display the dialog .Display ' \\Insert Shape Picture if the Name property (Filepath) <> "" ' \\ Set Left, Top, Width and Height properties to position the shape If .Name <> "" Then ActiveDocument.Shapes.AddPicture FileName:=.Name, _ LinkToFile:=False, _ SaveWithDocument:=True, _ Left:=120, _ Top:=20, _ Width:=150, _ Height:=150, _ Anchor:=Selection.Range End If End With ' \\ Clean up Set oDialog = Nothing End Sub

How to use:

  1. Open your Word document.
  2. Press Alt + F11 to open VBE.
  3. Insert-Module. (Insert -> module)
  4. Paste the code there in the window at right. (F7)
  5. Close VBE (Alt + Q or press the X in the top right hand corner).
  6. Save the file.
 

Test the code:

  1. Open the document
  2. To insert a picture as InlineShape choose:
  3. ALT+F8 and double click: InsertInlinePictureDialog
  4. To insert a picture as Shape choose:
  5. ALT+F8 and double click: InsertFlowtingPictureDialog
 

Sample File:

Insert picture dialog.zip 8.26KB 

Approved by mdmackillop


This entry has been viewed 254 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express