VBA Inserting 3 pictures in different cells and Columns

Dapante

New Member
Joined
May 12, 2020
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hi Everybody


Hope you and yours are Ok at this awful time....


I Need your expertise to solve a small Pickle ....


I Need a VBA Code. I'm doing a work diary. Where I add everyday 3 to 9 PICS of works being done on my construction site.


I want to insert 3 images from a specific folder. I want to select 3 image from my folder in one go!

When I use the code it should open the Folder automatically (Like ThisWorkbook.Path) the option "Application.GetOpenFilename" doesn't help me because I have to search every time the path of the folder. As my Pics and my sheet are in the same folder (everyday has different Pics and a copy of the same excel file), it would help to open it from there....


I have created a Botton, when I push it, it should:

Insert image 1, image 2 and image 3 (JPG, BMP, GIF, TIF, etc...) in different columns. The 3 Pics should be selected in one selection (in the Folder) and being automatically copied to following cells:

Image 1 to Cell L82:P88

Image 2 to Cell Q82:U88

Image 3 to Cell V82:Z88


They should adjust Left/Top and in Height and Width in the Number of rows (3 Columns x 7 Lines)

Something like this:

1st Line

(PIC 1 = 3 Columns x 7 Lines) | (PIC 2 = 3 Columns x 7 Lines) | (PIC 3 = 3 Columns x 7 Lines) End


2nd Line

(PIC 4 = 3 Columns x 7 Lines) | (PIC 5 = 3 Columns x 7 Lines) | (PIC 6 = 3 Columns x 7 Lines) End


and so on... (don't worry I can easily copy and make a new Bottom for each Line....)


I'm using some codes I found on the Net but can only get 1 image every-time in to the sheet... I don't want to have 1 Pic 1 Button.


Could you please help me. Thank you in advance for your help.
 

Attachments

  • Example Daniel.jpg
    Example Daniel.jpg
    141.9 KB · Views: 10

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Upvote 0
Thank you for your remarks. I will take it for the next Post. Stay safe #Stayhome
 
Upvote 0
"My Solution"

Sub Foto3()

Dim Pict
Dim ImgFileFormat As String
Dim Celula As String
Celula = "L102" ' celula que será inserido a imagem

ImgFileFormat = "All Picture Files(*.emf;*.wmf;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.bpm;*.gif;*.gfa;*.emz;*.wmz;*.pcz;*.tif;*.tiff;*.cgm;*.eps;*.pct;*.pict;*.wpg;*.pcd;*.pcx;*.cdr;*.fpx;*.mix), *.bmp"
'Pict = Application.GetOpenFilename(ImgFileFormat, False, False, MultiSelect:=True)

Pict = Application.GetOpenFilename(ImgFileFormat, False, False, False, True)

'If Pict = False Then End

If IsArray(Pict) Then 'IF ARRAY

If UBound(Pict) <= 3 Then 'IF I

j = 11

For i = LBound(Pict) To UBound(Pict)

Select Case i

Case 1 To 3
Application.ActiveSheet.Shapes.AddPicture Pict(i), False, True, Range(Celula).Left, _
Range(Celula).Top, Range(Celula).Width * 5, Range(Celula).Height * 7

j = j + 5
Celula = Chr(64 + j + 1) & "102"



End Select

Next i 'FOR I

Else 'IF I

MsgBox "Selecionar apenas 3 imagens"


End

End If

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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