Import and rotate image

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Hi,

I have a macro that imports image, and has worked out great until now. The problem now is that I need to rotate the picture 90#, and after it has been rotated I need it to "start" in a certain cell (B51).

I hope someone can help me to place the image in right cell :)

Code:
Sub InsertPicture()

Dim myPicture
Dim MyOpj As Object

myPicture = Application.GetOpenFilename _
("Bilder (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
, "Velg bilde som skal settes inn")
If VarType(myPicture) = vbBoolean Then Exit Sub

If myPicture = "False" Then Exit Sub

Set MyObj = Ark1.Pictures.Insert(myPicture)

    With MyObj
        With .ShapeRange
        .LockAspectRatio = msoFalse
        .IncrementRotation 90#
        .Height = 350
        .Width = 500
        .Top = Ark1.Range("B51").Top
        .Left = Ark1.Range("B51").Left
        End With
    .Placement = xlMoveAndSize
    End With

Set MyObj = Nothing

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It seems to do what you want , but this:-
Code:
Dim MyOpj As Object
Should be This:-
Code:
Dim MyObj As Object
 
Upvote 0
No, that didn't seem to fix it.
The problem is that it is originally inserted into correct cell (B51), but when it is rotated I think it rotates around its center point, and therefore the placement isn't correct.
 
Upvote 0
This should do what you want:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG27Apr34
[COLOR="Navy"]Dim[/COLOR] myPicture
[COLOR="Navy"]Dim[/COLOR] MyObj [COLOR="Navy"]As[/COLOR] Object
myPicture = Application.GetOpenFilename _
("Bilder (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
, "Velg bilde som skal settes inn")
[COLOR="Navy"]If[/COLOR] VarType(myPicture) = vbBoolean [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]If[/COLOR] myPicture = "False" [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]Set[/COLOR] MyObj = ActiveSheet.Pictures.Insert(myPicture)
 
    
    [COLOR="Navy"]With[/COLOR] MyObj
        [COLOR="Navy"]With[/COLOR] .ShapeRange
            .LockAspectRatio = msoFalse
            .IncrementRotation 90#
            .Height = 350
            .Width = 500
            .Left = Range("B52").Left - (.Width - .Height) / 2
            .Top = Range("B52").Top + (.Width - .Height) / 2
        [COLOR="Navy"]End[/COLOR] With
            .Placement = xlMoveAndSize
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] MyObj = Nothing
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,546
Members
449,169
Latest member
mm424

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