AddPictures, rotate image,

fonk

New Member
Joined
Mar 30, 2009
Messages
49
Hi all,
I'm using the following part of 'Biocie J's code to add pictures to a spreadsheet, format size and orientate for landscape, Problem being that if the picture gets rotated the handle position changes and the picture ends up either to the right or below where the insertion point (cell) is. Am I missing something or have the order incorrect? I've done a lot of searching and have not found a good explanation or way forward to remedy this.
Regards, Dave

Code:
Private Sub InsertPics()
Dim myPicture As String, MyObj As Object
Dim Cnt As Variant
Dim shp As shape
Dim itm As Variant
'Biocie J Code


Worksheets("Tooling Transfer Form").Activate
ActiveCell.Activate


    'Source of picture
myPicture = UserForm2.Tbo11.Value


If myPicture = "False" Then Exit Sub




Set MyObj = ActiveSheet.Shapes.AddPicture(myPicture, False, True, ActiveCell.Left, ActiveCell.Top, -1, -1)


    ' Check orientation for landscape

With MyObj
If MyObj.Rotation = 0 Or MyObj.Rotation = 180 Then
End If


If MyObj.Rotation = 90 Then
    .IncrementRotation 90#


End If
If MyObj.Rotation = 270 Then
   .IncrementRotation 90#
End If


  'Unlock aspect ratio to fit in box and size
    
MyObj.LockAspectRatio = msoFalse
    MyObj.Width = 217
        MyObj.Height = 135
End With
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi all,
Kept hacking around and finally figured a way to get what i was after, re-sized, then rotated if required, then cut and moved to original insert point. Code below.
Dave

Code:
Private Sub InsertPics()Dim myPicture As String, MyObj As Object


'Biocie J Code


Worksheets("Tooling Transfer Form").Activate
ActiveCell.Activate


    'Source of picture
myPicture = UserForm2.Tbo11.Value
If myPicture = "False" Then Exit Sub


Set MyObj = ActiveSheet.Shapes.AddPicture(myPicture, False, True, ActiveCell.Left, ActiveCell.Top, -1, -1)


'Unlock Aspect Raitio and resize picture
MyObj.LockAspectRatio = msoFalse
    MyObj.Width = 217
        MyObj.Height = 135


With MyObj
    If MyObj.Rotation = 0 Or MyObj.Rotation = 180 Then
Else


If MyObj.Rotation = 90 Then
    .IncrementRotation -90#
    
ElseIf MyObj.Rotation = 270 Then
   .IncrementRotation 90#


End If
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Cut
    ActiveCell.PasteSpecial
        ActiveCell.Select
        
End If
    
End With
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top