Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert multiple pictures every nth cell after last inserted picture

Status
Not open for further replies.

CutterJaxx

Technical User
Sep 17, 2008
8
AU
Hi all,

Running Windows XP, Excel 2003

I have a macro which allows me to insert pictures every nth cell with a predefined starting cell. As more pictures need to be added at a later date I need to facilitate the insertion of pictures after the last picture inserted and at the same intervals.

Can I either a:prompt the user for the new starting cell
or b: find the last inserted picture automatically and set the new starting cell based on its location.

Below is the existing code.

Code:
Sub Insert_Pict()
     
    Dim Pict() As Variant
    Dim ImgFileFormat As String
    Dim PictCell As Range
    Dim Ans As Integer
    Dim newPicture As Shape
    Dim lrow As Long, lLoop As Long
    Dim lTop As Long
    Dim sShape As Shape
     
    ImgFileFormat = "Image Files jpg (*.jpg),*.jpg,(*.bmp),others, tif (*.tif),*.tif"
     
GetPict:
    Pict = Application.GetOpenFilename(ImgFileFormat, MultiSelect:=True)
     'Note you can load in any nearly file format
    If Not IsArray(Pict) Then
        Debug.Print "No files selected."
        Exit Sub
    End If
     
    lrow = 3
    For lLoop = LBound(Pict) To UBound(Pict)
         
        lTop = Cells(lrow, "A").Top
        Set sShape = ActiveSheet.Shapes.AddPicture(Pict(lLoop), msoFalse, msoCTrue, Cells(1, 3).Left, lTop, 622, 467)
         'expression.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
    
    With sShape
        .LockAspectRatio = msoTrue
    End With
    
    lrow = lrow + 45
Next lLoop
End Sub

As always,
Any and all assistance greatly appreciated.
Cutter
 




Hi,

The LAST pic will be in row...
Code:
with activesheet
  with  .shapes(.shapes.count)
    lRow = .topleftcell.row
  end with
end with


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks heaps SkipVought,

I incorporated your code into mine and it does exactly what I wanted.

Thanks Again
Cutter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top