PDA

View Full Version : How to insert multiple images and words into table (word)?



aerodactel
05-27-2015, 11:05 AM
hi my name is Janna, could someone help me please, im doing my assignment and it requires me to add 100+ images and next to each image i have to insert their information like: tag,comment,modified time,changed time,accessed time, created time, size, and hash.

now the thing is i have the images and the informations (tag,comment,modified time,changed time,accessed time, created time, size, and hash) in a separate folder, and i require to put all of them together as a table in microsoft word.

so for example:the table will have the headings: images, tag,comment,modified time,changed time,accessed time, created time, size, and hash.

and under each heading i would like to put the images and their informations next to them.

But i have 100+ images, up to 300 images....

my assignment is due tomorrow:crying::crying::crying::crying:

pls could anyone help me to insert all the images and informations i have into word at once, instead of me copy and paste and write the information one by one.... plzzz

there must be a way...
Thank you, very much
janna.

gmayor
05-28-2015, 10:36 PM
You left this a bit late to ask for help! We are not going to do your homework for you, as that would not help you learn anything, but the following will help speed you on your way. You will have to modify the code to produce the results you want, particularly with respect to the Microsoft function used to get the file information, but I have included the link in the code.


Option Explicit

Sub AddGraphic()
'Graham Mayor 29 May 2015
Dim oTable As Table
Dim oCell As Range
Dim i As Long, iCount As Long
Dim strFile As String
Const strPath As String = "C:\Path\" 'The folder with the graphics
Documents.Add
Set oTable = ActiveDocument.Tables.Add(ActiveDocument.Range, 1, 2)
'adjust the width of the cells as required
strFile = Dir$(strPath & "*.jpg") 'The file extension of the graphics
iCount = 0
i = 1
While strFile <> ""
iCount = iCount + 1
strFile = Dir$()
Wend
strFile = Dir$(strPath & "*.jpg")
While strFile <> ""
Set oCell = oTable.Cell(i, 1).Range
oCell.End = oCell.End - 1
oCell.InlineShapes.AddPicture strPath & strFile
Set oCell = oTable.Cell(i, 2).Range
oCell.End = oCell.End - 1
oCell.Text = ShowFileAccessInfo(strPath & strFile)
i = i + 1
If i < iCount Then oTable.Rows.Add
strFile = Dir$()
Wend
lbl_Exit:
Exit Sub
End Sub


Function ShowFileAccessInfo(strFile As String) As String
'https://msdn.microsoft.com/en-us/library/office/gg251660.aspx?f=255&MSPPError=-2147217396
Dim fs As Object
Dim f As Object
Dim s As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFile)
s = UCase(strFile) & vbCrLf
s = s & "Created: " & f.DateCreated & vbCrLf
s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
ShowFileAccessInfo = s
lbl_Exit:
Exit Function
End Function