Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2019, 08:47 AM
Dzib Dzib is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2019
Novice
Macro to insert images in a document
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default Macro to insert images in a document

Hi,




I've found this macro that works fine to insert a whole folder of images in a word document. The only problem is that the images are inserted in a random order. Any idea how to insert them in alphabetical order?


Code:
Sub InsertSpecificNumberOfPictureForEachPage()
    Dim StrFolder As String
    Dim strFile As String
    Dim objDoc As Document
    Dim dlgFile As FileDialog
    Dim objInlineShape As InlineShape
    Dim nResponse As Integer
    Dim strPictureNumber As Integer
    Dim strPictureSize As String
    Dim n As Integer  
   
    Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
    
    With dlgFile
      If .Show = -1 Then
        StrFolder = .SelectedItems(1) & "\"
      Else
        MsgBox ("No Folder is selected!")
        Exit Sub
      End If
    End With
   
    strFile = Dir(StrFolder & "*.*", vbNormal)
    strPictureNumber = InputBox("Input the number of the picture for each page", "Picture Number", "For exemple: 1")
    n = 1  
   
    While strFile <> ""
      Selection.InlineShapes.AddPicture FileName:=StrFolder & strFile, LinkToFile:=False, SaveWithDocument:=True
      Selection.TypeParagraph
      Selection.Collapse Direction:=wdCollapsEnd
      Selection.TypeText Text:=Left(strFile, InStrRev(strFile, ".") - 1)
      Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
      If ActiveDocument.InlineShapes.Count = strPictureNumber * n Then
        Selection.InsertNewPage
        Selection.TypeBackspace
        n = n + 1
      End If
      Selection.TypeParagraph
      strFile = Dir()
    Wend
   
    For Each objInlineShape In ActiveDocument.InlineShapes
      objInlineShape.Select
      Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Next objInlineShape
   
    nResponse = MsgBox("Do you want to resize all pictures?", 4, "Resize Picture")
    If nResponse = 6 Then
      strPictureSize = InputBox("Input the height and width of the picture, seperated by comma", "Height and Width", "For exemple:500,500")
      For Each objInlineShape In ActiveDocument.InlineShapes
        objInlineShape.Height = Split(strPictureSize, ",")(0)
        objInlineShape.Width = Split(strPictureSize, ",")(1)
      Next objInlineShape
    End If
  End Sub
Reply With Quote
  #2  
Old 07-18-2019, 10:29 AM
gmaxey gmaxey is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

See Photo Gallery Add-In


And I have a premium version that does lots more.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-18-2019, 12:33 PM
Dzib Dzib is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2019
Novice
Macro to insert images in a document
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

Looks like it doesn't work with Office 2019
Reply With Quote
  #4  
Old 07-18-2019, 01:44 PM
gmaxey gmaxey is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

That isn't very helpful. What isn't working?


Please try again with the attached and let me know what (if any errors) you get. Are you using a 64 bit version of Office?
Attached Files
File Type: dotm Photo Gallery (Basic) Add-In Ver 3.5.dotm (336.5 KB, 16 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-18-2019, 11:31 PM
Dzib Dzib is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2019
Novice
Macro to insert images in a document
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
That isn't very helpful. What isn't working?


Please try again with the attached and let me know what (if any errors) you get. Are you using a 64 bit version of Office?
Don't know why but it didn't worked at home but works fine at work. Thank you so much.
I'll try again and let you know 😉
Reply With Quote
  #6  
Old 07-19-2019, 08:10 AM
gmaxey gmaxey is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Did you use the file I attached at work or the one you downloaded? I expect the issue is with a 64 bit version of office installed at home and I don't think the file on the website was updated to account for that. Please try the file I attached both at home and work and advise if you have issues.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 07-20-2019, 01:47 AM
Dzib Dzib is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2019
Novice
Macro to insert images in a document
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

I've used the file attached at work and the downloaded at home.
Now the attached one works perfectly fine at home too
Reply With Quote
  #8  
Old 07-20-2019, 08:27 AM
gmaxey gmaxey is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Ok, the website is updated with the file I sent you as an attachment. Thanks.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 07-24-2019, 06:20 AM
Dzib Dzib is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2019
Novice
Macro to insert images in a document
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

Thanks gmaxey for this amazing tool, save me lot of time...
One question, is it possible to have a custom caption text that saves in configuration window?
I use the text Foto (in dutch) but I have to rewrite it every time I insert new pictures.
Reply With Quote
  #10  
Old 07-24-2019, 06:38 AM
gmaxey gmaxey is offline Macro to insert images in a document Windows 10 Macro to insert images in a document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Yes, it is possible and wouldn't take any more effort than the "Donate" button which you are apparently yet to discover!!


If you want, contact me privately to arrange fee based consulting services.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro: insert muliple images and resize into given cells marco83 Excel Programming 1 08-15-2018 09:16 AM
Macro to insert images in a document Insert multiple images into Word document from smartphone james1979uk Drawing and Graphics 1 06-06-2018 01:12 AM
Macro to insert images in a document Insert pictures in yahoo images into a Word document nasserlouis Word VBA 3 08-20-2017 02:06 PM
Macro to insert images in a document Insert multiple images & controls into a document vanwijnen Word VBA 1 06-05-2015 06:16 AM
Macro to insert images in a document Macro to create tables around all images in document lsmcal1984 Word VBA 4 12-01-2013 06:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:36 AM.


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