![]() |
|
#1
|
|||
|
|||
|
Hi everyone,
I need to create a Script, who allow to import all the picture inside a folder in a Table in Word. - Every picture must stay in a different cell. - The table has 2 Row, all the picture have to stay in the links row. I've found this script that allow to import all the picture form a folder into a word document, but i've no idea how modify it, so that he can import them into a Table. Code:
Sub InsertImage()
Dim FolderPath, objFSO, Folder, ImagePath, image
Const END_OF_STORY = 6
Const MOVE_SELECTION = 0
FolderPath = Select_Folder_From_Prompt
If InStr(FolderPath, "EMPTY") = 0 Then
Set objFSO = CreateObject("Scripting.Filesystemobject")
Set Folder = objFSO.GetFolder(FolderPath)
For Each image In Folder.Files
ImagePath = image.Path
If CheckiImageExtension(ImagePath) = True Then
'Insert the images into the word document
Application.Selection.EndKey END_OF_STORY, MOVE_SELECTION
Application.Selection.InlineShapes.AddPicture (ImagePath)
Application.Selection.InsertBreak 'Insert a pagebreak
End If
Next
End If
End Sub
Function Select_Folder_From_Prompt() As String
Dim fd, bMultiSelect, CONST_MODEL_DIRECTORY
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select a folder"
.AllowMultiSelect = bMultiSelect
.InitialFileName = CONST_MODEL_DIRECTORY
.Filters.Clear
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
Select_Folder_From_Prompt = .SelectedItems(1) & "\"
Else
Select_Folder_From_Prompt = "EMPTY"
End If
End With
End Function
Function CheckiImageExtension(ImagePath)
Dim varArray ' An array contains iamge file extensions.
Dim varEach ' Each iamge file extension.
Dim blnIsPptFile ' Whether the file extension is image file extension.
Dim objFSO, file, FileExtension
Set objFSO = CreateObject("Scripting.Filesystemobject")
Set file = objFSO.GetFile(ImagePath)
FileExtension = file.Name
blnIsPptFile = False
If FileExtension <> "" Then
varArray = Array(".emf", ".wmf", ".jpg", ".jpeg", ".jfif", ".png", ".jpe", ".bmp", ".dib", ".rle", ".gif", ".emz", ".wmz", ".pcz", ".tif", ".tiff", ".eps", ".pct", ".pict", ".wpg")
For Each varEach In varArray
If InStrRev(UCase(FileExtension), UCase(varEach)) <> 0 Then
blnIsPptFile = True
Exit For
End If
Next
End If
CheckiImageExtension = blnIsPptFile
Set objFSO = Nothing
Set file = Nothing
End Function
|
|
#2
|
||||
|
||||
|
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you!!
|
|
| Tags |
| picture, table |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Importing number data from an Excel spreadsheet into a Word table | Hefty | Word Tables | 1 | 06-07-2017 04:08 AM |
Importing Data from Excel - Format of table messed up in Word Table
|
epsulliv | Word Tables | 6 | 08-24-2015 07:29 AM |
Automatic change of Picture Captions...
|
pawleex | Word | 1 | 08-04-2013 05:04 PM |
Problem with automatic table of contents
|
pogonoforysci1 | Word | 14 | 04-14-2013 10:39 PM |
Formatting automatic table of contents
|
1234msaps | Word | 3 | 10-31-2012 02:26 PM |