Solved

Need Word Macro to Select Graphics Files and Insert Each Separated by Hard Return

Posted on 2012-03-13
4
433 Views
Last Modified: 2012-03-17
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 files would then be inserted into the document:
Graphics File 1
Paragraph Mark
Graphics File 2
Paragraph Mark
Graphics File 3
Paragraph Mark
...
Last File
Paragraph Mark
0
Comment
Question by:Alex972
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37717431
Have you tried recording one? That should get you started.
0
 
LVL 1

Author Comment

by:Alex972
ID: 37731165
I recorded the following macro.

There are several limitations that I would like help fixing:
1) The folder that will be used will differ each time I use it.
2) The number of pictures chosen will vary each time I use ti.
3) The pictures come in touching other.  
    I want two or more hard returns/paragraph marks between them.
    (see Before and After Pictures below).

Sub GetPix()
'
' GetPix Macro
'
'
    Selection.InlineShapes.AddPicture FileName:="U:\Captures\11-1027-00.jpg", _
        LinkToFile:=False, SaveWithDocument:=True
    ActiveWindow.ActivePane.SmallScroll Down:=-119
End Sub

Open in new window

Before.jpg
After.jpg
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37731555
This uses the Office File dialogue to select the files which are placed after the current selection.
Sub InsertPics()
    Dim fd As FileDialog
    Dim rng As Range
    Dim ilsh As InlineShape
    
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    Dim strFileName As Variant
    
    With fd
        .Filters.Clear
        .Filters.Add "All files", "*.*"
        .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
        If .Show Then
            Set rng = Selection.Range
            rng.Collapse wdCollapseEnd
            For Each strFileName In .SelectedItems
                Set ilsh = ActiveDocument.InlineShapes.AddPicture(strFileName, False, True, rng)
                Set rng = ilsh.Range
                rng.Collapse wdCollapseEnd
                rng.Text = vbCr & vbCr
                rng.Collapse wdCollapseEnd
            Next strFileName
        End If
    End With

End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Alex972
ID: 37732578
Thanks, just what I was looking for.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question