Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2017, 08:01 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Windows 10 I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2,"
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Question I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2,"


Can anyone help?

I need a document that will allow me to insert a folders worth of pictures at once (could vary from 10 photos to 500/1000) automatically (the photos all need to be the same size when inserted). I'm looking at four pictures to a page (2 columns of 2) with a slight space between. Ideally, I need a caption box underneath each picture automatically numbering (Photograph No 1, Photograph No 2 etc.) where I can then type descriptions for each photo. I currently have a macro that does exactly this but only 2 photos to a page. Any ideas would be very much appreciated. (Running on Office 365)
Reply With Quote
  #2  
Old 11-13-2017, 10:14 AM
Souriane Souriane is offline I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Office 2013
Advanced Beginner
 
Join Date: Feb 2017
Location: Quebec, Canada
Posts: 82
Souriane is on a distinguished road
Default

Hi!

It would be easier if you would submit the macro you actually use so we can adapt it!

Souriane
Reply With Quote
  #3  
Old 11-13-2017, 01:43 PM
macropod's Avatar
macropod macropod is offline I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could also save yourself (and others) a lot of time if you did a forum search. The code in this thread https://www.msofficeforums.com/drawi...ument-all.html does something very close to what you're after. With a few minor edits, it could do exactly what you say you want.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 11-13-2017, 10:07 PM
gmayor's Avatar
gmayor gmayor is offline I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Windows 10 I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See http://www.gmayor.com/photo_gallery_template.html which will insert pictures in two columns, with numbered captions, though on a typical portrait oriented page there will be six to a page unless you increase the top or bottom margin. However I would suggest inserting in smaller batches than 500 or more.

Photograph No is not one of the default captions included, but you can type it in the Configuration.

Note that this will produce huge documents, which may be an issue depending on what you intend to do with the document. You can choose to insert as links but that will require user access to the original files.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 11-14-2017, 02:22 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Windows 10 I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2," Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with "Photograph No 1, 2,"
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

Thanks all for answering and apologies for my lack of knowledge my first time here or using a forum like this I tried doing a search but I'm not entirely sure how to word it to get the best result. I'll take a look at your suggestions. In the meantime, if you are still happy to have a look, the macro that I am using is this one:

Code:
Sub PSoC()
'
' PSoC Macro
'
'
Sub AddPics()
    Application.ScreenUpdating = False
    Dim i As Long, j As Long, c As Long, r As Long, NumCols As Long
    Dim oTbl As Table, TblWdth As Single, StrTxt As String, RwHght As Single
    On Error GoTo ErrExit
    NumCols = CLng(InputBox("How Many Columns per Row?"))
    RwHght = CSng(InputBox("What row height for the pictures, in inches (e.g. 1.5)?"))
    On Error GoTo 0
     'Select and insert the Pics
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select image files and click OK"
        .Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.bmp; *.tif; *.png"
        .FilterIndex = 2
        If .Show = -1 Then
             'Add a 2-row by NumCols-column table to take the images
            Set oTbl = Selection.Tables.Add(Range:=Selection.Range, NumRows:=2, NumColumns:=NumCols)
            With ActiveDocument.PageSetup
                TblWdth = .PageWidth - .LeftMargin - .RightMargin - .Gutter
            End With
            With oTbl
                .AutoFitBehavior (wdAutoFitFixed)
                .Columns.Width = TblWdth / NumCols
            End With
            CaptionLabels.Add Name:="Picture"
            For i = 1 To .SelectedItems.Count Step NumCols
                r = ((i - 1) / NumCols + 1) * 2 - 2
                 'Format the rows
                Call FormatRows(oTbl, r, RwHght)
                For c = 1 To NumCols
                    j = j + 1
                     'Insert the Picture
                    ActiveDocument.InlineShapes.AddPicture _
                    FileName:=.SelectedItems(j), LinkToFile:=False, _
                    SaveWithDocument:=True, Range:=oTbl.Cell(r, c).Range
                     'Get the Image name for the Caption
                    StrTxt = Split(.SelectedItems(j), "\")(UBound(Split(.SelectedItems(j), "\")))
                    StrTxt = ": " & Split(StrTxt, ".")(0)
                     'Insert the Caption on the row below the picture
                    With oTbl.Cell(r + 1, c).Range
                        .InsertBefore vbCr
                        .Characters.First.InsertCaption _
                        Label:="Picture", Title:=StrTxt, _
                        Position:=wdCaptionPositionBelow, ExcludeLabel:=False
                        .Characters.First = vbNullString
                        .Characters.Last.Previous = vbNullString
                    End With
                     'Exit when we're done
                    If j = .SelectedItems.Count Then Exit For
                Next
                 'Add extra rows as needed
                If j < .SelectedItems.Count Then
                    oTbl.Rows.Add
                    oTbl.Rows.Add
                End If
            Next
        Else
        End If
    End With
ErrExit:
    Application.ScreenUpdating = True
End Sub
 '
Sub FormatRows(oTbl As Table, x As Long, Hght As Single)
    With oTbl
        With .Rows(x)
            .Height = InchesToPoints(Hght)
            .HeightRule = wdRowHeightExactly
            .Range.Style = "Normal"
        End With
        With .Rows(x + 1)
            .Height = CentimetersToPoints(0.5)
            .HeightRule = wdRowHeightExactly
            .Range.Style = "Caption"
        End With
    End With
End Sub
 
Sub Macro1()
'
' Macro1 Macro
'
'
    ActiveWindow.Close
End Sub

Any help would be appreciated.

Last edited by macropod; 11-14-2017 at 03:07 AM. Reason: Added code tags
Reply With Quote
  #6  
Old 11-14-2017, 03:09 AM
macropod's Avatar
macropod macropod is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The link I posted includes a link to instructions for macro installation and usage. You evidently haven't followed those; otherwise you wouldn't have the macro from that post embedded in another one. The code simply won't work that way. Time to start over.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 11-14-2017, 03:19 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

The code that I copied across allows me to insert two pics per page with a separate cell under each with "Photograph No 1". This is a doc that I use all the time and something that a friend showed me - I'm not even going to pretend that I know anything about all of this wonderful stuff!!! If you say what I'm after isn't possible....I'll take your word for it.
Reply With Quote
  #8  
Old 11-14-2017, 03:22 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

Thanks for your reply.
Reply With Quote
  #9  
Old 11-14-2017, 03:35 AM
macropod's Avatar
macropod macropod is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by NewbieLearning View Post
If you say what I'm after isn't possible....I'll take your word for it.
That is not what I said. The AddPics code you posted is a direct lift from https://www.msofficeforums.com/word-...-pictures.html. As I said, you have it embedded in another macro [Sub PSoC()]. Either that or there's an error in how you've posted it.

In any event, your claim "I currently have a macro that does exactly this but only 2 photos to a page" does not accord with the code you've posted, since that code can insert dozens of images per page if you set the parameters appropriately at the prompts.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 11-14-2017, 03:48 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

Right, ok. I think I follow. More than likely there is an error in how I posted it!! I've been trying to fiddle with it but I'm not getting anywhere.


It's obviously the parameters which are incorrect. I wasn't aware that I could change these - I've just always used it as was.
Reply With Quote
  #11  
Old 11-14-2017, 04:02 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

I have now changed the "table" that the photos are inserted to. I can get the two columns i.e. 4 photos cells per page but the photos only insert down the left hand side, so Photograph No. 1, 3, 5 etc.
Reply With Quote
  #12  
Old 11-14-2017, 04:30 AM
macropod's Avatar
macropod macropod is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by NewbieLearning View Post
It's obviously the parameters which are incorrect. I wasn't aware that I could change these - I've just always used it as was.
I fail to see how you could not be aware, when the code asks:
"How Many Columns per Row?"
"What row height for the pictures, in inches (e.g. 1.5)?"

I have no idea what you mean by
Quote:
Originally Posted by NewbieLearning View Post
I have now changed the "table" that the photos are inserted to.
since the macro creates its own table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 11-14-2017, 04:34 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

When I run the word document that contains this macro, a word document opens up with a table of two rows in it. There is a pop up at the top that says "enable content", I press this which allows me to chose which pictures I want to insert into the doc. That is as much as I know...so I am quite impressively, it would seem, not aware of a lot.
Reply With Quote
  #14  
Old 11-14-2017, 04:35 AM
NewbieLearning NewbieLearning is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 10 I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2016
Novice
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot;
 
Join Date: Nov 2017
Posts: 9
NewbieLearning is on a distinguished road
Default

When I mentioned having changed the table, the changes that I made were to the two line table that appears when I open the word doc.
Reply With Quote
  #15  
Old 11-14-2017, 04:55 AM
macropod's Avatar
macropod macropod is offline I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Windows 7 64bit I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

...
Quote:
Originally Posted by NewbieLearning View Post
When I run the word document that contains this macro, a word document opens up with a table of two rows in it.
The macro is coded to insert as many pictures as you want anywhere in a document. There is no need for a 'starting' table. Simply click on wherever you want to insert your pictures, then run the macro. If you do that within another table, that will interfere with the macro's normal operation, as it will cause Word to create a new table within the existing one (which you probably don't want). It seems whoever gave you the code didn't invest much effort explaining what it does...
Quote:
Originally Posted by NewbieLearning View Post
There is a pop up at the top that says "enable content", I press this which allows me to chose which pictures I want to insert into the doc.
Unless there's some other code in the document, the AddPics macro won't run automatically - you'd have to run it via Alt-F8, for example. If it's running automatically, I suggest ditching that document and creating a new one with the code from https://www.msofficeforums.com/drawi...ument-all.html. Do read the instructions there, and in Installing Macros.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set "insert page break after" as a style formatting feature? dra_gon Word 7 03-31-2017 08:32 AM
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; When applying styles word is automatically reverting to "strong" style partway through my document Victoria S Word 3 11-17-2015 12:51 PM
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Problem with "Next page" section break automatically turning into "Odd or Even Page" c_gallagher25 Word 1 02-12-2014 04:27 PM
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; Macro to print "Current Page" in Word 2010 Jshopping Word VBA 10 06-08-2012 01:15 AM
I need a macro to automatically insert 4 pics per page in a word document with &quot;Photograph No 1, 2,&quot; "Grow a document' with text automatically added to new page bpercival Word 1 02-07-2012 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft