Saltar al contenido principal

¿Cómo insertar varias imágenes con nombre de archivo en un documento de Word?

En un documento de Word, puede insertar rápidamente varias imágenes a la vez mediante la función Insertar. Pero, a veces, debe insertar la ruta del archivo y los nombres como título al insertar las imágenes. ¿Cómo podría lidiar con esta tarea en un archivo de Word?

Inserte varias imágenes con nombre de archivo usando el código VBA

Inserte varias imágenes con nombre de archivo usando Kutools para Word


Inserte varias imágenes con nombre de archivo usando el código VBA

El siguiente código VBA puede ayudarlo a insertar la ruta del archivo y el nombre como título al insertar las imágenes, haga lo siguiente:

1. Mantenga pulsado el ALT + F11 teclas para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. Y luego, haga clic en recuadro > Módulo, copie y pegue el código siguiente en el módulo en blanco abierto:

Código VBA: inserte varias imágenes con el nombre de archivo:

Sub PicWithCaption()
    Dim xFileDialog As FileDialog
    Dim xPath, xFile As Variant
    On Error Resume Next
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    If xFileDialog.Show = -1 Then
        xPath = xFileDialog.SelectedItems.Item(1)
        If xPath <> "" Then
            xFile = Dir(xPath & "\*.*")
            Do While xFile <> ""
                If UCase(Right(xFile, 3)) = "PNG" Or _
                    UCase(Right(xFile, 3)) = "TIF" Or _
                    UCase(Right(xFile, 3)) = "JPG" Or _
                    UCase(Right(xFile, 3)) = "GIF" Or _
                    UCase(Right(xFile, 3)) = "BMP" Then
                    With Selection
                        .InlineShapes.AddPicture xPath & "\" & xFile, False, True
                        .InsertAfter vbCrLf
                        .MoveDown wdLine
                        .Text = xPath & "\" & xFile & Chr(10)
                        .MoveDown wdLine
                    End With
                End If
                xFile = Dir()
            Loop
        End If
    End If
End Sub

3. Entonces presione F5 para ejecutar este código, se muestra una ventana de exploración, seleccione la carpeta que contiene las imágenes que desea insertar, vea la captura de pantalla:

doc insertar imágenes con nombre de archivo 1

4. Luego haga clic OK , todas las imágenes en la carpeta seleccionada se han insertado en el documento de Word, y la ruta del archivo y el nombre se insertan como título, mira la captura de pantalla:

doc insertar imágenes con nombre de archivo 2


Inserte varias imágenes con nombre de archivo usando Kutools para Word

Si tiene Kutools for Word, Con su Imágenes función, puede insertar rápidamente varias imágenes con la ruta del archivo y el nombre en el documento de Word inmediatamente.

Kutools for Word : con más de 100 prácticos complementos de Word, prueba gratuita y sin límite en 60 días. 

Después de instalar Kutools for Word, haz lo siguiente:

1. Haga Clic en Kutools > Imágenes, ver captura de pantalla:

doc insertar imágenes con nombre de archivo 3

2. En el estalló Insertar imágenes cuadro de diálogo, realice las siguientes operaciones:

  • (1.) Haga clic en agregar archivos or Agregar carpeta botón para seleccionar las imágenes que desea insertar;
  • (2.) Luego verifique Inserte la ruta del archivo de cada imagen como título opción en la parte inferior izquierda del cuadro de diálogo;
  • (3.) Y luego haga clic en recuadro del botón.

doc insertar imágenes con nombre de archivo 4

3. Después de insertar las imágenes, verá que la ruta del archivo de cada imagen y el nombre también se insertan, vea la captura de pantalla:

doc insertar imágenes con nombre de archivo 5

¡Haga clic para descargar Kutools para Word y una prueba gratuita ahora!

Las mejores herramientas de productividad de oficina

Kutools for Word - Mejore su experiencia con Word con Over 100 ¡Características notables!

🤖 Asistente de IA de Kutools: Transforma tu escritura con IA - Generar contenido  /  Reescribir texto  /  Resumir documentos  /  Solicite información basado en el documento, todo dentro de Word

📘 Dominio del documento: Dividir páginas  /  Combinar documentos  /  Exportar selección en varios formatos (PDF/TXT/DOC/HTML...)  /  Convertir por lotes a PDF  /  Exportar páginas como imágenes  /  Imprima varios archivos a la vez...

Edición de contenidos: Buscar y reemplazar por lotes en varios archivos  /  Cambiar el tamaño de todas las imágenes  /  Transponer filas y columnas de tabla  /  Convertir tabla en texto...

🧹 Limpieza sin esfuerzo: barrer Espacios extra  /  Saltos de sección  /  Todos los encabezados  /  Cuadros de texto  /  Los hipervínculos  / Para obtener más herramientas de extracción, diríjase a nuestro Quitar grupo...

Inserciones creativas: Insertar Mil Separadores  /  Casillas de verificación  /  Botones de radio  /  Código QR   /  Barcode  /  Tabla de líneas diagonales  /  Título de la ecuación  /  Captura de imagen  /  Pie de tabla  /  Varias imágenes  / Descubre más en el Insertar grupo...

🔍 Selecciones de precisión: Localizar páginas específicas  /  tablas  /  formas  /  párrafos de encabezado  / Mejorar la navegación con más, Seleccionar características...

Mejoras de estrellas: Navegue rápidamente a cualquier ubicación  /  insertar automáticamente texto repetitivo  /  alternar sin problemas entre ventanas de documentos  /  11 herramientas de conversión...

👉 ¿Quieres probar estas funciones? Kutools para Word ofrece una prueba gratuita de 60 días.¡Sin limitaciones! 🚀
 
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
VBA CODE IS VERY USEFULLY MY DATA VALIDATE IMAGES SHARING.
This comment was minimized by the moderator on the site
How can I decrease the overall size of the photo so there are multiple per page?
This comment was minimized by the moderator on the site
Is there a way to insert each picture and file name per page? Sometimes if one picture is too big the file name will then go to the next page or if picture is too small the next picture will be together in one page instead on the next page
This comment was minimized by the moderator on the site
Hello, Rizza,
To insert each picture and file name per page, please apply the following vba code:
Sub PicWithCaption()
    Dim xFileDialog As FileDialog
    Dim xPath As String, xFile As String
    On Error Resume Next
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    If xFileDialog.Show = -1 Then
        xPath = xFileDialog.SelectedItems.Item(1)
        If xPath <> "" Then
            xFile = Dir(xPath & "\*.*")
            Do While xFile <> ""
                If UCase(Right(xFile, 3)) = "PNG" Or _
                    UCase(Right(xFile, 3)) = "TIF" Or _
                    UCase(Right(xFile, 3)) = "JPG" Or _
                    UCase(Right(xFile, 3)) = "GIF" Or _
                    UCase(Right(xFile, 3)) = "BMP" Then
                    
                    ' Add the picture
                    Selection.InlineShapes.AddPicture xPath & "\" & xFile, False, True
                    Selection.TypeParagraph
                    
                    ' Add the file path below the picture
                    Selection.TypeText xPath & "\" & xFile
                    Selection.TypeParagraph
                    
                    ' Move to the next page
                    Selection.InsertBreak Type:=wdPageBreak
                End If
                xFile = Dir()
            Loop
        End If
    End If
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
A problem occurs when the file name to be added exceeds 10.

pic1
pic10
pic11
pic12
pic2
pic3
pic4
pic5...
This comment was minimized by the moderator on the site
change the file name to 01, 02, 03 and it will work
This comment was minimized by the moderator on the site
Wow this is great! I only needed the file name, so I deleted "xPath & "\" &" from the .Text line and that worked perfectly. Thanks for this!
This comment was minimized by the moderator on the site
Which line of code would you change and how to have the file path written before the picture, aka the caption (filename) is above rather than below.
This comment was minimized by the moderator on the site
With Selection
.Text = xFile
.InlineShapes.AddPicture xPath & "\" & xFile, False, True
.InsertAfter vbCrLf
.MoveDown wdLine

End With
This comment was minimized by the moderator on the site
Have to add this .MoveDown wdLine after .Text=xFile
This comment was minimized by the moderator on the site
buenas noches amigo me ha servido mucho su información sinembargo me surge una duda cree que es posible incertar imagenes en word de la misma manera pero dentro de celdas incertadas?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations