Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-29-2022, 02:07 PM
elias17 elias17 is offline Insert multiple pictures at once in Word table Windows 11 Insert multiple pictures at once in Word table Office 2021
Novice
Insert multiple pictures at once in Word table
 
Join Date: Nov 2022
Posts: 3
elias17 is on a distinguished road
Default Insert multiple pictures at once in Word table

Hi,


I have an inventory list where each item has a unique ID (called "Kürzel") based on its category in the format A 01, A 02, A 03, E 01, E 02 etc. Each item has a QR-Code (PNG File) with the same ID as a text value.
Screenshot 2.jpg


I now want to print out physical labels to then put on the items. Therefore I have a word template with a table. Each Label has two columns, one for the picture of the QR-Code and one for the text.
Screenshot 1.jpg


And this brings me to my question. I would like to insert all images at once (at least per column) so I do not have to do it indiviually. I found a great VBA code from this thread that I modified a bit:
Code:
Sub InsertMultipleImagesFixed()
 Dim fd As FileDialog
 Dim oTable As Table
 Dim iRow As Integer
 Dim iCol As Integer
 Dim oCell As Range
 Dim i As Long
 Dim sNoDoc As String
 Dim picName As String
 Dim scaleFactor As Long
 Dim max_height As Single
 'define resize constraints
 max_height = 275



 Set fd = Application.FileDialog(msoFileDialogFilePicker)
 With fd
 .Title = "Select image files and click OK"
 .Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.bmp; *.tif; *.png; *.wmf"
 .FilterIndex = 2
 If .Show = -1 Then

 For i = 1 To .SelectedItems.Count

 iCol = 1
 iRow = i
 'get filename
 picName = Right(.SelectedItems(i), Len(.SelectedItems(i)) - InStrRev(.SelectedItems(i), "\"))
 'remove extension from filename ****
 picName = Left(picName, InStrRev(picName, ".") - 1)

 'select cell
 Set oCell = ActiveDocument.Tables(1).Cell(iRow, iCol).Range

 'insert image
 oCell.InlineShapes.AddPicture FileName:= _
 .SelectedItems(i), LinkToFile:=False, _
 SaveWithDocument:=True, Range:=oCell

 'resize image
 If oCell.InlineShapes(1).Height > max_height Then
 scale_factor = oCell.InlineShapes(1).ScaleHeight * (max_height / oCell.InlineShapes(1).Height)
 oCell.InlineShapes(1).ScaleHeight = scale_factor
 oCell.InlineShapes(1).ScaleWidth = scale_factor
 End If

 'center content
 oCell.ParagraphFormat.Alignment = wdAlignParagraphCenter

 Next i
 End If
 End With

 Set fd = Nothing
 End Sub
This works almost perfectly but there are two problems. It always inserts the pictures in the first column. I would like the images images that I select to paste into the column which I have currently selected. Also, if possible, it would be nice if the pictures had the following attributes:
  • Width and Height: 0,8cm
  • Layout options: In Front of Text and Fix position on page
  • Centered verically and horizontally
I would be very grateful if someone could help me out with modifying the code!


Thanks
Elias
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert multiple pictures at once in Word table Mac - Macro insert pictures in table Nina Word VBA 16 08-27-2018 01:53 AM
Insert multiple pictures at once in Word table Macro to insert multiple pictures with adjustable column size nando88 Word VBA 6 05-09-2016 11:56 PM
Insert multiple pictures at once in Word table Insert an article with pictures into a table cell skatiemcb Word Tables 2 01-24-2015 08:18 AM
Insert multiple pictures at once in Word table Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Insert multiple pictures at once in Word table Resize multiple pictures in a Word 2010 table JBA479 Word VBA 1 01-24-2014 08:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:12 AM.


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