Word Macro

nianchi111

Board Regular
Joined
Aug 24, 2007
Messages
197
Office Version
  1. 365
Hi,

Is this is possible.

- Import all the images found inside a folder at the following location "C:\ImportImages"

vertically with one space in between them and - Resize the imported images so they take

up half the width of the standard A4 page in Word.

I create a report in Word on a regular basis, the first thing I do is resize and import photos taken from a digital camera or drawings from a folder.
__________________
Thanks,
Nianchi111.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
in the past I used to take an A4 sheet and insert newspaper columns, in you case 2 columns, and then insert the pics with a macro, and let word deal with the spacing. I used this for a photo contact sheet, you can modify to use 3, 4 columns

I have the macro at home and will post the code later
 
Upvote 0
Try something based on:
Code:
Sub InsertAllPics()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, Rng As Range
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.jpg", vbNormal)
With ActiveDocument
  While strFile <> ""
    Set Rng = .Range.Characters.Last
    With Rng
      .InsertAfter vbCr
      .Collapse wdCollapseEnd
      .InlineShapes.AddPicture FileName:=strFolder & "\" & strFile, _
        LinkToFile:=False, SaveWithDocument:=True
      With .Paragraphs.Last.Range.InlineShapes(1)
        .LockAspectRatio = msoTrue
        .Width = CentimetersToPoints(7.5)
      End With
    End With
    strFile = Dir()
  Wend
End With
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
The above code allows you to select the folder. As coded, it looks for jpg files. you can change the file type.
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,380
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top