Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2020, 07:39 PM
Roes14 Roes14 is offline Word VBA, images Windows 10 Word VBA, images Office 2016
Novice
Word VBA, images
 
Join Date: Jul 2020
Posts: 1
Roes14 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-16-2020, 07:50 PM
gmayor's Avatar
gmayor gmayor is offline Word VBA, images Windows 10 Word VBA, images Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,219
gmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of light
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Images gone from a word doc. radaway Word 2 07-12-2018 12:52 AM
Word VBA, images How to link images by default when dragging images in word maxbaeten Drawing and Graphics 3 09-27-2017 11:34 PM
Word VBA, images 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
Word VBA, images Mail Mege Images - Path Correct but Images Repeated Sonia Sosa Mail Merge 8 04-22-2011 03:05 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:18 PM.


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