#1
|
|||
|
|||
Word VBA, images
I need to complete a macro that inserts images from a folder and put under each one its file name, then resize them, then select them and put a black border to each image and its name, I have the following macro but I can't get you to select them to give them the border
--------------------------------------------------------------------------------------------------- Sub InsertSpecificNumberOfPictureForEachPage() Dim xDlg As FileDialog Dim xFilePath As String Dim xFileName As String Dim xMsbBoxRtn As Long Dim xPicSize As String Dim xShape As InlineShape Set xDlg = Application.FileDialog(msoFileDialogFolderPicker) If xDlg.Show = -1 Then xFilePath = xDlg.SelectedItems(1) & "" Else Exit Sub End If xFileName = Dir(xFilePath & "*.*", vbNormal) While xFileName <> "" If Not (Right(xFileName, 4) = ".png" Or Right(xFileName, 4) = ".bmp" _ Or Right(xFileName, 4) = ".jpg" Or Right(xFileName, 4) = ".ico") Then GoTo LblCtn End If With Selection .InlineShapes.AddPicture xFilePath & xFileName, False, True .TypeParagraph .Collapse wdCollapsEnd .TypeText Left(xFileName, InStrRev(xFileName, ".") - 1) .ParagraphFormat.Alignment = wdAlignParagraphCenter .TypeParagraph End With LblCtn: xFileName = Dir() Wend ActiveDocument.InlineShapes(1).Select Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter xMsbBoxRtn = MsgBox("desea redimensionar las imagenes?", vbYesNo, "Kutools for Word") If xMsbBoxRtn = 6 Then xPicSize = InputBox("inserte el alto y ancho de las imagenes separado por coma", "Kutools for Word", "") End If For Each xShape In ActiveDocument.InlineShapes xShape.Height = Split(xPicSize, ",")(0) xShape.Width = Split(xPicSize, ",")(1) Next xShape End Dim i As Long With ActiveDocument Dim img As InlineShape For Each img In ActiveDocument.InlineShapes img.Select With img.Borders(wdBorderLeft) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = wdColorBlack End With With img.Borders(wdBorderRight) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = wdColorBlack End With With img.Borders(wdBorderTop) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = wdColorBlack End With With img.Borders(wdBorderBottom) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth150pt .Color = wdColorBlack End With Next img End End With End Sub ------------------------------------------------------------------------------------------------ If you could help me, I'd be very grateful |
#2
|
||||
|
||||
Rather than re-invent the wheel, take a look at Photo Gallery Add-in Template which will do what you require.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Images gone from a word doc. | radaway | Word | 2 | 07-12-2018 12:52 AM |
How to link images by default when dragging images in word | maxbaeten | Drawing and Graphics | 3 | 09-27-2017 11:34 PM |
Opening all selected images, resizing images and placing them into a table. | John Livewire | Word VBA | 1 | 09-15-2017 11:24 PM |
ms word 2013 massively increases file size of images inserted into new word document | rbg | Drawing and Graphics | 0 | 06-05-2016 08:04 AM |
Mail Mege Images - Path Correct but Images Repeated | Sonia Sosa | Mail Merge | 8 | 04-22-2011 03:05 PM |