MooseMaster05
New Member
- Joined
- Jun 5, 2015
- Messages
- 7
Hello, I created a macro in excel 2010 that sizes and inserts images into a named cell based on the file name of that image. When I ran the macro in excel 2013 it runs with no errors, sizes the image appropriately but inserts the image in the incorrect location. Was there a change between these two versions of excel that would cause this? Any help would be appreciated. The code were the error must be occurring is listed below I also included my variable definitions.
Dim myPicture As String
Dim myRange As Range
Dim mySheet As Integer
Dim myPath As String
Dim StepNumber As Integer
Dim lastPicFound As Integer
Dim pagesRequired As Integer
Dim pagesToAdd As Integer
Dim pic As Shape
'begin inserting pictures
StepNumber = 1
Do While StepNumber <= lastPicFound
myPicture = myPath & "\" & CStr(StepNumber) & ".JPG"
If Dir(myPicture) <> "" Then
mySheet = StepNumber \ 12 + 1
If StepNumber Mod 12 = 0 Then
mySheet = StepNumber \ 12
End If
Set myRange = Worksheets(mySheet + 1).Range("PICTURE_" & CStr(StepNumber - (mySheet - 1) * 12))
Set p = Worksheets(mySheet + 1).Shapes.AddPicture(myPicture, False, True, myRange.Width, myRange.Height, myRange.Left, myRange.Top)
If myRange.Cells.Count = 1 Then Set myRange = myRange.MergeArea
With myRange
p.Top = .Top
p.Left = .Left
p.Width = .Height
p.LockAspectRatio = msoFalse
p.Height = .Width
With p
.Rotation = 90
.IncrementLeft p.Height / 2 - p.Width / 2
.IncrementTop p.Width / 2 - p.Height / 2
.ZOrder msoSendToBack
End With
End With
End If
StepNumber = StepNumber + 1
Loop
Dim myPicture As String
Dim myRange As Range
Dim mySheet As Integer
Dim myPath As String
Dim StepNumber As Integer
Dim lastPicFound As Integer
Dim pagesRequired As Integer
Dim pagesToAdd As Integer
Dim pic As Shape
'begin inserting pictures
StepNumber = 1
Do While StepNumber <= lastPicFound
myPicture = myPath & "\" & CStr(StepNumber) & ".JPG"
If Dir(myPicture) <> "" Then
mySheet = StepNumber \ 12 + 1
If StepNumber Mod 12 = 0 Then
mySheet = StepNumber \ 12
End If
Set myRange = Worksheets(mySheet + 1).Range("PICTURE_" & CStr(StepNumber - (mySheet - 1) * 12))
Set p = Worksheets(mySheet + 1).Shapes.AddPicture(myPicture, False, True, myRange.Width, myRange.Height, myRange.Left, myRange.Top)
If myRange.Cells.Count = 1 Then Set myRange = myRange.MergeArea
With myRange
p.Top = .Top
p.Left = .Left
p.Width = .Height
p.LockAspectRatio = msoFalse
p.Height = .Width
With p
.Rotation = 90
.IncrementLeft p.Height / 2 - p.Width / 2
.IncrementTop p.Width / 2 - p.Height / 2
.ZOrder msoSendToBack
End With
End With
End If
StepNumber = StepNumber + 1
Loop