Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub LoadByPicture()
- Const ROW_FIRST = 2
- Const COL_ID = 1
- Const COL_LOADED = 2
- Const COL_BARCODE = 3
- Dim pictname As String
- Dim pictpath As String
- Dim pictext As String
- Dim pastehere As Range
- Dim pasterow As Long
- Dim i As Long
- Dim lastrow As Long
- Dim pict As Picture
- Dim pictloaded As Boolean
- On Error Resume Next
- pictpath = "D:\Dev\AGC\barcodes\barcode_"
- pictext = ".png"
- lastrow = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
- For i = ROW_FIRST To lastrow
- Set pastehere = Cells(i, COL_BARCODE)
- pasterow = pastehere.Row
- Cells(pasterow, COL_BARCODE).Select
- pictname = Cells(i, COL_ID)
- '/// Check to see if any of the pictures in the current sheet
- '/// have the same position as the cell in the current row,
- '/// if they do, we already have a barcode loaded.
- pictloaded = False
- For Each pict In ActiveSheet.Pictures
- If pict.TopLeftCell = Cells(i, COL_BARCODE) Then
- pictloaded = True
- Exit For
- End If
- Next
- If Not pictloaded Then
- ActiveSheet.Pictures.Insert(pictpath & pictname & pictext).Select
- With Selection
- .Left = Cells(pasterow, COL_BARCODE).Left
- .Top = Cells(pasterow, COL_BARCODE).Top
- .ShapeRange.LockAspectRatio = msoTrue
- .ShapeRange.Height = 80#
- .ShapeRange.Width = 80#
- .ShapeRange.Rotation = 0#
- End With
- End If
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement