Hepl with Import picture in Excel

KlausW

Active Member
Joined
Sep 9, 2020
Messages
395
Office Version
  1. 2016
Platform
  1. Windows
Hi, I found this code from Barb Henderson.
Works great. j I have a small challenge, in column B, starting with B2 are the names of the images to be imported, for this I use a formula. Sometimes the cell is empty, but there is still a formula in it.

So, I get this error in this line.

ActiveSheet.Pictures.Insert("C:\Users\k-wit\Documents\Rejseafregning\" & pictname & ".png").Select 'Path to where pictures are stored

Someone who can help, all help will be appreciated.

Best regards Klaus W
 

Attachments

  • Skærmbillede (6).png
    Skærmbillede (6).png
    46.9 KB · Views: 13

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Maybe:
VBA Code:
If Len(Trim(pictname)) > 0 Then
  ActiveSheet.Pictures.Insert("C:\Users\k-wit\Documents\Rejseafregning\" & pictname & ".png").Select 'Path to where pictures are stored
End If
 
Upvote 0
No I got an error in
.Left = Cells(pasterow, 2).Left + (Cells(pasterow, 3).Width - .Width / 1)
 
Upvote 0
Forgot VBA code.

VBA Code:
Sub Rektangelafrundedehjørner1_Klik()

Dim pictname As String
Dim pastehere As Range
Dim pasterow As Long
Dim x As Long
Dim lastrow As Long

lastrow = Worksheets("Billeter").Range("B1").CurrentRegion.Rows.Count
x = 2
For x = 2 To lastrow
Set pastehere = Cells(x, 1)
pasterow = pastehere.Row
Cells(pasterow, 1).Select 'This is where picture will be inserted

pictname = Cells(x, 2) 'This is the picture name
If Len(Trim(pictname)) > 0 Then
ActiveSheet.Pictures.Insert("C:\Users\k-wit\Documents\Rejseafregning\" & pictname & ".png").Select 'Path to where pictures are stored
End If

With Selection

.Left = Cells(pasterow, 2).Left + (Cells(pasterow, 3).Width - .Width / 1)
.Top = Cells(pasterow, 2).Top + (Cells(pasterow, 1).Height - .Height / 1.1)



.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 370#
.ShapeRange.Width = 470#
.ShapeRange.Rotation = 0#
End With

Next


End Sub
 
Upvote 0
The code should look for the last cell in column B include image names, not the formula stated in.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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