Place in cell

Silverwolph

New Member
Joined
Oct 10, 2022
Messages
11
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hey can anyone help me with a VBA code i cant figure out how to do.
I cant to take all png files from C:\pictures\ and have it place them in cell just like if you use the function place in cell when inserting a picture
I´ve tried all different tings but i still get the pictures over the cell.
I´ve even tried to record a macro to see what the function is called and its "Selection.InsertPictureInCell" but that will depend on a file name
and my idea was to just have it take all png files from the folder.
Does anyone have any experience with this, i did look at some of the posts but they seem to be more a statement that the function is here.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Here is some simple code to insert PNG files from a a single folder into cells. You can change the IniPath to your liking. Put your cursor where you want to start pasting the pictures.

VBA Code:
Sub InsertAllPNGFiles()

  Dim Cel As Range
  Dim PathFile As String
  Dim FN As String
  Dim IniPath As String
  Dim X As Long
  Dim TLCel As Range
 
  IniPath = "C:\Temp\"
  Application.EnableEvents = False
 
  FN = Dir(IniPath & "*.png")
  Set TLCel = Selection.Resize(1, 1)
  X = -1
 
  Do While FN <> ""
    PathFile = IniPath & FN
    X = X + 1
    TLCel.Offset(X, 0).Select
    Selection.InsertPictureInCell (PathFile)
    FN = Dir
  Loop
 
  Application.EnableEvents = True
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

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