-
Inserting a directory of images in a word???
Hello,
I'm thinking in a program that insert pics into a Word document and manipulating them. I am new to this myself and need to do something similar. In this case, I want to insert multiple pics into a document, but I WOULD LIKE INSERT A COMPLETE DIRECTORY OF PICS and then scale each one to some size. I then want to print the document.
I am looking others codes and I have finding this:
----------------------------------------------
[vba] Sub pega_fotos()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oDummy As Word.InlineShape
Dim i As Long
Set oWord = New Word.Application
Set oDoc = oWord.Documents.Open(FileName:="C:\blank.doc")
oWord.Visible = True
' insert 2 picture files (bitmaps)
Set oDummy = oDoc.InlineShapes.AddPicture(FileName:="Z:\COGNODATA\Proyectos\BCOP - Funcional Datamart Marketing\An?lisis\An?lisis Descriptivos\AUDITOR?A\BDMI_MUNI2\fig_BDMI_MUNI2_x0x5BEMPRESAS_CARACTE RISTICAS_TIPO_ACTIVOS_TOT0x5D.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
Set oDummy = oDoc.InlineShapes.AddPicture(FileName:="Z:\COGNODATA\Proyectos\BCOP - Funcional Datamart Marketing\An?lisis\An?lisis Descriptivos\AUDITOR?A\BDMI_MUNI2\fig_BDMI_MUNI2_x0x5BEMPRESAS_CARACTE RISTICAS_TIPO_AGRARIO_POR0x5D.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
' insert n picture files (bitmaps)
For i = 1 To oDoc.InlineShapes.Count
' scale it
oDoc.InlineShapes(i).Fill.Visible = False
oDoc.InlineShapes(i).Fill.Transparency = 0#
oDoc.InlineShapes(i).Line.Weight = 0.75
oDoc.InlineShapes(i).Line.Transparency = 0#
oDoc.InlineShapes(i).Line.Visible = False
oDoc.InlineShapes(i).LockAspectRatio = True
oDoc.InlineShapes(i).Height = 200
oDoc.InlineShapes(i).Width = 200
oDoc.InlineShapes(i).PictureFormat.Brightness = 0.5
oDoc.InlineShapes(i).PictureFormat.Contrast = 0.5
oDoc.InlineShapes(i).PictureFormat.CropLeft = 0#
oDoc.InlineShapes(i).PictureFormat.CropRight = 0#
oDoc.InlineShapes(i).PictureFormat.CropTop = 0#
oDoc.InlineShapes(i).PictureFormat.CropBottom = 0#
Next
'clear memory
Set oDummy = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub[/vba] ----------------------------------------
~~ Code tags added by Oorang
The problem is that i only can insert 2 images, but i want insert 400 images in a directory, i have to read the names automatically and insert this...
Any info appreciated... Thanks
Ps: Excuse for me english.
-
I suppose you are doing this within word itself (tested on word 2003). This is for gif images in a certain directory.[VBA]Sub pega_fotos()
'loop for shapes
Dim i As Long
'name of picture
Dim v_filename As String
'path of pictures
Dim v_path As String
'directory of your pictures
v_path = "C:\Pictures\*.gif"
v_filename = Dir(v_path)
'loop through your pictures
Do While v_filename <> ""
Application.ActiveDocument.InlineShapes.AddPicture FileName:= _
Left(v_path, Len(v_path) - 5) & v_filename, _
LinkToFile:=False, SaveWithDocument:=True
v_filename = Dir
Loop
'loop through the added shapes
For i = 1 To Application.ActiveDocument.InlineShapes.Count
With ActiveDocument.InlineShapes(i)
.Fill.Visible = False
.Fill.Transparency = 0#
.Line.Weight = 0.75
.Line.Transparency = 0#
.Line.Visible = False
.LockAspectRatio = True
.Height = 200
.Width = 200
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.PictureFormat.CropLeft = 0#
.PictureFormat.CropRight = 0#
.PictureFormat.CropTop = 0#
.PictureFormat.CropBottom = 0#
End With
Next i
End Sub[/VBA]
Charlize
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules