Pagina precedente | 1 | Pagina successiva
Vota | Stampa | Notifica email    
Autore

VBA centrare immagine in una cella

Ultimo Aggiornamento: 07/03/2019 10:22
Post: 1
Registrato il: 06/03/2019
Città: MILANO
Età: 37
Utente Junior
2016
OFFLINE
06/03/2019 19:44

Ciao a tutti

La macro va ad aprire una cartella in cui selezionando l'immagine voluta questa viene ridimensionata in funzione della cella di destinazione.

Non riesco a centrare la foto.

Il codice è il seguente:

Sub InsertImageFromFolder()
Dim myPicture As String, myRange As Range 'set of variables for the image and a selected cell
'defining image formats for import
myPicture = Application.GetOpenFilename _
("Pictures (.gif; .jpg; .bmp; .tif),.gif; .jpg; .bmp; .tif", _
, "Choose image for insert")
Set myRange = Selection 'defining the selected cells
'Set myRange = Application.InputBox("Select your range...", Type:=8) 'message to select the destination cell - option
InsertAndSizePic myRange, myPicture 'calling the procedure for resizing images
End Sub


Sub InsertAndSizePic(Target As Range, PicPath As String)
'procedure to insert a picture and adjust the size of the destination cell
Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top + (.Height - p.Height) / 2
p.Left = .Left + (.Width - p.Width) / 2
p.Width = .Width * 0.95
p.Height = .Height * 0.95
End With
End Sub

In allegato trovate il file excel.

Grazie per l'aiuto
[Modificato da mat.p 06/03/2019 19:47]
Post: 2.170
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
07/03/2019 10:22

Ciao

modifica:

.....
With Target
p.ShapeRange.LockAspectRatio = msoFalse
p.Width = .Width * 0.95
p.Height = .Height * 0.95
p.Top = .Top + (.Height - p.Height) / 2
p.Left = .Left + (.Width - p.Width) / 2
End With
....

saluti



[Modificato da dodo47 07/03/2019 10:24]
Domenico
Win 10 - Excel 2016
Vota:
Amministra Discussione: | Chiudi | Sposta | Cancella | Modifica | Notifica email Pagina precedente | 1 | Pagina successiva
Nuova Discussione
 | 
Rispondi
Cerca nel forum
Tag discussione
Discussioni Simili   [vedi tutte]
Feed | Forum | Bacheca | Album | Utenti | Cerca | Login | Registrati | Amministra
Tutti gli orari sono GMT+01:00. Adesso sono le 00:59. Versione: Stampabile | Mobile | Regolamento | Privacy
FreeForumZone [v.6.1] - Copyright © 2000-2024 FFZ srl - www.freeforumzone.com