Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-09-2017, 12:27 PM
michissimo michissimo is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Oct 2017
Posts: 4
michissimo is on a distinguished road
Default Automatic picture importing into a table

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
Can someone help me?
Reply With Quote
  #2  
Old 10-09-2017, 01:26 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

See: http://www.msofficeforums.com/word-v...html#post47919
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 10-10-2017, 01:54 AM
michissimo michissimo is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Oct 2017
Posts: 4
michissimo is on a distinguished road
Default

Thank you!!
Reply With Quote
Reply

Tags
picture, table

Thread Tools
Display Modes


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


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


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft