PDA

View Full Version : Attaching Objects Code



godsowndevil
05-27-2008, 08:14 AM
Hi,

I have an excel sheet where 1 column has certain text. I have PDF files in a folder & they are saved as per the text in the column.

For Example, if the column E1 has text "ABC_1234", there is a pdf saved by the same name and so on.

I need a code that will look at the text in the column, go to a given folder & attach the corresponding PDF's in another column.

I have a code that activates attaching objects, but I am not sure on how to get it to certain folders/files.

My code is as below:

Sub Attach_Objects

Range("A1").Select
Selection.End(xlToRight).Select
Selection.Copy
Application.CutCopyMode = False
ActiveSheet.OLEObjects.Add(ClassType:="AcroExch.Document", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe", IconIndex:=1, _
IconLabel:="").Activate
Selection.ShapeRange.PictureFormat.CropRight = 17.25
Selection.ShapeRange.PictureFormat.CropBottom = 22.51
Selection.ShapeRange.PictureFormat.CropLeft = 19.5
Selection.ShapeRange.PictureFormat.CropBottom = 21.76

End Sub

godsowndevil
05-28-2008, 10:25 AM
I forgot to mention that the number of objects to be attached may vary from 10 to over 300. I think to cover that part I could use:

For x = 1 to 1000
If Cells(x,3).Value = "" Then
x = 1001
Else
(Start & Continue with attaching objects)
End If
Next x