Problem in Picture alignment
Dear Joel,
Thanks for your message. I have tried to check as your suggestion.
I found it seems that the problem happened to certain pictures. I put the
problematic pictures to whatever rows,it comes with the position problem.
And I found new more question. When I run the macro,and it finished. I copy
the part nos. to other rows, the macro still run. why? what is the problem?
"joel" wrote:
Is the problem always with the same picture or same row in the worksheet?
Try placing the picture in a different row or putting a different picture in
the row to determine if the problem is with certain pictures or certain rows.
You may have hidden rows or merged cells that is causing the problem. The
picture may be cropped and that is causing the problem. I don't think the
porblem is with the code itself, just something we are not expecting.
"Li Jianyong" wrote:
Dear Joel,
I have tried to change the code as your suggestion. But I have the same
problem in the position of the picture. When i work with few item,like 20
items, it works fine. but when I work on many items,like 200 items. The
problem happened. The problem is:
.topatl.offset(0,1).top . Not as code instruction: .top=atl.offset(0,1).top
please try to figure out the problem for me
Best regards
Li Jianyong
"joel" wrote:
from:
.Left = atl.Offset(0, 1).Left
.Top = atl.Offset(0, 1).Top
to:
.Left = atl.Offset(0, 1).Left
.Top = atl.Offset(0, 1).Top
.width = atl.Offset(0, 1).width
.height = atl.Offset(0, 1).height
"Li Jianyong" wrote:
Hello Sirs,
I have programmed following code to insert pictures into my sheet. But I
found there is problem in code line:.Top = atl.Offset(0, 1).Top
My pictures exact position shp.top is bigger than the range
-atl.offset(0,1).top
please check for me and provide help
thanks advancely
Code as below:
Sub insertpic()
Dim shp As Picture
Dim atl As Range
Dim lujing As String
lujing = "G:\Autoline Tensioner"
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
For Each atl In Selection
With atl
.RowHeight = 102.75
With .EntireRow
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With
atl.Offset(0, 1).ColumnWidth = 22.75
Next
For Each atl In Selection
On Error Resume Next
With atl.Offset(0, 1)
Set shp = .Parent.Pictures.Insert(lujing & "\" & atl.Value & ".jpg")
End With
If Err.Number = 0 Then
With shp
.Left = atl.Offset(0, 1).Left
.Top = atl.Offset(0, 1).Top
.Height = 100
.Width = 133
End With
Else
atl.Offset(0, 1).Value = "No existed picture"
atl.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
On Error GoTo 0
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
|