Link to home
Start Free TrialLog in
Avatar of Alex Campbell
Alex CampbellFlag for United States of America

asked on

How do I insert graphics into Word with multiple hard returns between graphics?

I need to select multiple graphics from a directory, insert them into a document
AND have them separated by a hard return.

If I use Insert, Picture, From File, the graphics are put right next to each other with no space and no paragraph mark between the graphics. This makes it extremely difficult to add text between the graphics.

I don't want to have to add the graphics individually because there are so many.

I have also tried it with creating a table and then adding the graphics, but in that case they are put next one another in one cell.

Is there a macro that will do this OR an option to set?
ASKER CERTIFIED SOLUTION
Avatar of Carol Chisholm
Carol Chisholm
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex Campbell

ASKER

I need to be able to start a macro in a new or existing document that will:
1. Allow me to go to a folder.
2. Select individual graphics files in the folder.
3. Click on OK.
4. The graphics would inserted into the document:
Graphics file 1
Paragraph Mark
File 2
Paragraph Mark
File 3
Paragraph Mark
...
Last File
Paragraph Mark

Warning: I found macro that did this for table (see code), but I think a simpler macro would be better for what I need.  I would want this new macro to be simpler.
I was told that there is a bug in VBA that does not work with the files in the order that you select them.  
Sub AddPix()
    Dim fd As FileDialog
    
    Set DataList = CreateObject("System.Collections.ArrayList")
 
     
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitContent
    
     Selection.MoveRight Unit:=wdCell
  
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
 
    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    
    Dim vrtSelectedItem As Variant
 
    'Use a With...End With block to reference the FileDialog object.
    With fd
        'Add a filter that includes GIF and JPEG images and make it the second item in the list.
        .Filters.Add "Images", "*.gif; *.jpg; *.jpeg"
 
        'Sets the initial file filter to number 2.
        .FilterIndex = 2
 
    'Use the Show method to display the File Picker dialog box and return the user's action.
        'If the user presses the action button...
        If .Show = -1 Then
 
            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
 
                DataList.Add (vrtSelectedItem)
            Next
            DataList.Sort
 
            For Each strItem In DataList
 
 
            'strItem is a String that contains the path of each selected item.
                  
                 Selection.InlineShapes.AddPicture FileName:= _
                  strItem _
                , LinkToFile:=False, SaveWithDocument:=True
                
                'Does this create extra row? No
                Selection.MoveRight Unit:=wdCell
                Selection.MoveRight Unit:=wdCell
            
            Next
        'If the user presses Cancel...
        Else
        End If
    End With
    Selection.HomeKey Unit:=wdStory
    Selection.Rows.HeadingFormat = wdToggle
    Selection.Rows.HeadingFormat = wdToggle
    'Set the object variable to Nothing.
    Set fd = Nothing
 
End Sub

Open in new window