ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting Pictures (https://www.excelbanter.com/excel-programming/358457-inserting-pictures.html)

mudraker[_356_]

Inserting Pictures
 

Using a Macro I need to insert various jpg pictures into an Excel
sheet.

These pictures are various sizes and need to be resized to the same
size.

Using VBA Is is possible to size a picture to a specific size? or to
get its current size and then calculate the % scaling required.


thanks in advance


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=531391


Greg Wilson

Inserting Pictures
 
Try:

Sub InsertPicts()
Dim P As Picture
Dim FNm As Variant
Dim R As Single
Dim c As Range

Set c = Cells(3, 3)
With Application
FNm = .GetOpenFilename("Picture files(*.jpg), *.jpg")
If VarType(FNm) = vbBoolean Then Exit Sub
.ScreenUpdating = False
Set P = ActiveSheet.Pictures.Insert(FNm)
R = P.Width / P.Height
P.Top = c.Top
P.Left = c.Left
P.Height = 350
P.Width = R * P.Height 'correct proportionality after resizing
.ScreenUpdating = True
End With
End Sub

Pictures are now "Hidden Members" and we're supposed to use the shape
object's AddPicture method. The problem with AddPicture is that the height
and width properties are required arguments. So how does one know the
appropriate proportionality since picture files come in different shapes and
sizes ? I know I'm missing something here and am quite interested if someone
has the answer.

Regards,
Greg

"mudraker" wrote:


Using a Macro I need to insert various jpg pictures into an Excel
sheet.

These pictures are various sizes and need to be resized to the same
size.

Using VBA Is is possible to size a picture to a specific size? or to
get its current size and then calculate the % scaling required.


thanks in advance


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=531391



David McRitchie

Inserting Pictures
 
Why not just do it with a photo editor in batch mode beforehand, you can do that with
IrfanView (irfanview.com) and many other free applications.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"mudraker" wrote in message
...

Using a Macro I need to insert various jpg pictures into an Excel
sheet.

These pictures are various sizes and need to be resized to the same
size.

Using VBA Is is possible to size a picture to a specific size? or to
get its current size and then calculate the % scaling required.


thanks in advance


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=531391




[email protected]

Inserting Pictures
 
This a code written in VB.net.
In searches for all BMP files in the folder, resize it and save it to
JPEG.

Hope this will help.


Sub Main()
Dim objFile As FileInfo
Dim objFolder As New DirectoryInfo("C:\Photo\BMP")
Dim objFolderFI As FileInfo() = objFolder.GetFiles("*.bmp")
Dim jpgFileName As String

For Each objFile In objFolderFI
Dim objBMP As New Bitmap("C:\Photo\BMP\" & objFile.Name)
objBMP = New Bitmap(objBMP, New Size(150, 150))
jpgFileName = Left(objFile.Name, Len(objFile.Name) - 3) &
"jpg"
Console.WriteLine("Converting C:\Photo\BMP\" &
objFile.Name)
objBMP.Save("C:\Photo\JPG\" & jpgFileName,
ImageFormat.Jpeg)
Next
End Sub



All times are GMT +1. The time now is 04:44 PM.

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