|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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) |
#2
|
|||
|
|||
Hi!
It would be easier if you would submit the macro you actually use so we can adapt it! Souriane |
#3
|
||||
|
||||
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] |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
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] |
#7
|
|||
|
|||
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.
|
#8
|
|||
|
|||
Thanks for your reply.
|
#9
|
||||
|
||||
Quote:
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] |
#10
|
|||
|
|||
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. |
#11
|
|||
|
|||
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.
|
#12
|
||||
|
||||
Quote:
"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 since the macro creates its own table.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
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.
|
#14
|
|||
|
|||
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.
|
#15
|
||||
|
||||
...
Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
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 |
When applying styles word is automatically reverting to "strong" style partway through my document | Victoria S | Word | 3 | 11-17-2015 12:51 PM |
Problem with "Next page" section break automatically turning into "Odd or Even Page" | c_gallagher25 | Word | 1 | 02-12-2014 04:27 PM |
Macro to print "Current Page" in Word 2010 | Jshopping | Word VBA | 10 | 06-08-2012 01:15 AM |
"Grow a document' with text automatically added to new page | bpercival | Word | 1 | 02-07-2012 03:33 PM |