Place in cell

Silverwolph

New Member
Joined
Oct 10, 2022
Messages
13
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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 1
Solution
Hmm nothing seems to be happening when running the code, and i did change the path
 
Upvote 0
Strange. I ran through a test and it did insert some pictures. Can you try stepping through the debugger and see what each filename is in the DO loop? Does it show real files?
 
Upvote 0
That was weird, tried it again and not it works like intended, thank you very much!
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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