ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Resize the image in excel 2007 (https://www.excelbanter.com/excel-programming/387039-resize-image-excel-2007-a.html)

Akader

Resize the image in excel 2007
 
Dear All
I have below code it's to insert photo in the cell and adjust the size
automatically as the row and Colum width and height, it's working perfect in
excel 2003, but in excel 2007 not working as I need, now only inserting the
photo without adjust it automatically .

Can anyone help me to modify the code to work in excel 2007

=============

Sub GetPhotoone()
Dim myPict As Picture
Dim myPictName As String
Dim rng As Range

Set rng = ActiveCell
myPictName = rng
With ActiveSheet
With .Range("AA1:AA50")


If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set TopCell = ActiveCell Else
Set TopCell = ActiveCell.End(xlUp)
If IsEmpty(ActiveCell.Offset(1, 0)) Then Set BottomCell = ActiveCell
Else Set BottomCell = ActiveCell.End(xlDown)
Range(TopCell, BottomCell).Select


Set myPict = .Parent.Pictures.Insert(filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)


End With
End With
End Sub

=============

many thanks

Abdul Kader


Akader

Resize the image in excel 2007
 
please can anyone help me

Dave Peterson

Resize the image in excel 2007
 
You may want to just include the part of the code that actually matters to see
if that helps.

(Untested)

Option Explicit
Sub GetPhotoone()

Dim rng As Range

Set rng = ActiveCell
myPictName = rng.Value

Set myPict = .Parent.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)

End Sub


Rng was set to the activecell. All that other stuff didn't really matter (and
didn't compile for me in xl2003).





Akader wrote:

Dear All
I have below code it's to insert photo in the cell and adjust the size
automatically as the row and Colum width and height, it's working perfect in
excel 2003, but in excel 2007 not working as I need, now only inserting the
photo without adjust it automatically .

Can anyone help me to modify the code to work in excel 2007

=============

Sub GetPhotoone()
Dim myPict As Picture
Dim myPictName As String
Dim rng As Range

Set rng = ActiveCell
myPictName = rng
With ActiveSheet
With .Range("AA1:AA50")

If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set TopCell = ActiveCell Else
Set TopCell = ActiveCell.End(xlUp)
If IsEmpty(ActiveCell.Offset(1, 0)) Then Set BottomCell = ActiveCell
Else Set BottomCell = ActiveCell.End(xlDown)
Range(TopCell, BottomCell).Select


Set myPict = .Parent.Pictures.Insert(filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)

End With
End With
End Sub

=============

many thanks

Abdul Kader


--

Dave Peterson

Akader

Resize the image in excel 2007
 
thank s Dave

same problem for this code also, it's only adjust Height size , i need from
the code to adjust the Width & Height dynamically same as the row & column
size


"Dave Peterson" wrote:

You may want to just include the part of the code that actually matters to see
if that helps.

(Untested)

Option Explicit
Sub GetPhotoone()

Dim rng As Range

Set rng = ActiveCell
myPictName = rng.Value

Set myPict = .Parent.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)

End Sub


Rng was set to the activecell. All that other stuff didn't really matter (and
didn't compile for me in xl2003).




NickHK

Resize the image in excel 2007
 
I don't use the 2007 version, but maybe look into the LockAspectRatio
property.

NickHK

"Akader" wrote in message
...
thank s Dave

same problem for this code also, it's only adjust Height size , i need

from
the code to adjust the Width & Height dynamically same as the row & column
size


"Dave Peterson" wrote:

You may want to just include the part of the code that actually matters

to see
if that helps.

(Untested)

Option Explicit
Sub GetPhotoone()

Dim rng As Range

Set rng = ActiveCell
myPictName = rng.Value

Set myPict = .Parent.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)

End Sub


Rng was set to the activecell. All that other stuff didn't really

matter (and
didn't compile for me in xl2003).






Dave Peterson

Resize the image in excel 2007
 
I tested this in xl2007 and the code put the picture entirely in the
activecell. Isn't that what you want? The size of the cell determines the size
of the picture??????

(Same code with all the declarations.)

Option Explicit
Sub GetPhotoone()

Dim rng As Range
Dim myPictName As String
Dim myPict As Picture

Set rng = ActiveCell
myPictName = Activecell.Value

Set myPict = ActiveSheet.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & Cells(1).Address(0, 0)

End Sub




Akader wrote:

thank s Dave

same problem for this code also, it's only adjust Height size , i need from
the code to adjust the Width & Height dynamically same as the row & column
size


"Dave Peterson" wrote:

You may want to just include the part of the code that actually matters to see
if that helps.

(Untested)

Option Explicit
Sub GetPhotoone()

Dim rng As Range

Set rng = ActiveCell
myPictName = rng.Value

Set myPict = .Parent.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)

End Sub


Rng was set to the activecell. All that other stuff didn't really matter (and
didn't compile for me in xl2003).




--

Dave Peterson

Akader

Resize the image in excel 2007
 
Dear Dave
this code in excel 2003 was working great like this.
in case the cell size is :
height 156 x Width 70 then when i run the code , the picture will resize
automatic in the cell with size of 156x70,

but now in 2007 the code is not changing the size automatically of picture
same as height and width like what excel 2003 was doing,

I hope now it's clear to you.

Regards

Abdul Kader


"Dave Peterson" wrote:

I tested this in xl2007 and the code put the picture entirely in the
activecell. Isn't that what you want? The size of the cell determines the size
of the picture??????

(Same code with all the declarations.)

Option Explicit
Sub GetPhotoone()

Dim rng As Range
Dim myPictName As String
Dim myPict As Picture

Set rng = ActiveCell
myPictName = Activecell.Value

Set myPict = ActiveSheet.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & Cells(1).Address(0, 0)

End Sub



Dave Peterson


Dave Peterson

Resize the image in excel 2007
 
It was clear to me before.

I tested it in xl2007 and it worked fine. I'm not sure why it's not working for
you.

If you changed the code, you may want to post what you actually used.



Akader wrote:

Dear Dave
this code in excel 2003 was working great like this.
in case the cell size is :
height 156 x Width 70 then when i run the code , the picture will resize
automatic in the cell with size of 156x70,

but now in 2007 the code is not changing the size automatically of picture
same as height and width like what excel 2003 was doing,

I hope now it's clear to you.

Regards

Abdul Kader

"Dave Peterson" wrote:

I tested this in xl2007 and the code put the picture entirely in the
activecell. Isn't that what you want? The size of the cell determines the size
of the picture??????

(Same code with all the declarations.)

Option Explicit
Sub GetPhotoone()

Dim rng As Range
Dim myPictName As String
Dim myPict As Picture

Set rng = ActiveCell
myPictName = Activecell.Value

Set myPict = ActiveSheet.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & Cells(1).Address(0, 0)

End Sub



Dave Peterson


--

Dave Peterson

Akader

Resize the image in excel 2007
 
I am using same code which you have post , if possible try to use same code
in xl2003 and see the diff.

Regards

Abdul Kader

"Dave Peterson" wrote:

It was clear to me before.

I tested it in xl2007 and it worked fine. I'm not sure why it's not working for
you.

If you changed the code, you may want to post what you actually used.



Akader wrote:

Dear Dave
this code in excel 2003 was working great like this.
in case the cell size is :
height 156 x Width 70 then when i run the code , the picture will resize
automatic in the cell with size of 156x70,

but now in 2007 the code is not changing the size automatically of picture
same as height and width like what excel 2003 was doing,

I hope now it's clear to you.

Regards

Abdul Kader

"Dave Peterson" wrote:

I tested this in xl2007 and the code put the picture entirely in the
activecell. Isn't that what you want? The size of the cell determines the size
of the picture??????

(Same code with all the declarations.)

Option Explicit
Sub GetPhotoone()

Dim rng As Range
Dim myPictName As String
Dim myPict As Picture

Set rng = ActiveCell
myPictName = Activecell.Value

Set myPict = ActiveSheet.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & Cells(1).Address(0, 0)

End Sub



Dave Peterson


--

Dave Peterson


Dave Peterson

Resize the image in excel 2007
 
First, if you're using the same code that I posted, it didn't work. The "option
explicit" line forced the declaration of the variables--so the code wouldn't
even compile.

Second, I used the corrected code and it worked exactly the same way in xl2003
as it did in xl2007.



Akader wrote:

I am using same code which you have post , if possible try to use same code
in xl2003 and see the diff.

Regards

Abdul Kader

"Dave Peterson" wrote:

It was clear to me before.

I tested it in xl2007 and it worked fine. I'm not sure why it's not working for
you.

If you changed the code, you may want to post what you actually used.



Akader wrote:

Dear Dave
this code in excel 2003 was working great like this.
in case the cell size is :
height 156 x Width 70 then when i run the code , the picture will resize
automatic in the cell with size of 156x70,

but now in 2007 the code is not changing the size automatically of picture
same as height and width like what excel 2003 was doing,

I hope now it's clear to you.

Regards

Abdul Kader

"Dave Peterson" wrote:

I tested this in xl2007 and the code put the picture entirely in the
activecell. Isn't that what you want? The size of the cell determines the size
of the picture??????

(Same code with all the declarations.)

Option Explicit
Sub GetPhotoone()

Dim rng As Range
Dim myPictName As String
Dim myPict As Picture

Set rng = ActiveCell
myPictName = Activecell.Value

Set myPict = ActiveSheet.Pictures.Insert(Filename:=myPictName)

myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & Cells(1).Address(0, 0)

End Sub



Dave Peterson


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 01:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com