VBA Import Image

JustinLock

New Member
Joined
Sep 22, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Having a few issues with Excel embedding the chosen image in excel for other user once file has been shared.

Images are not networked and I would need the document to save the designated images to the allocated cell(s) so that they can be viewed by anyone that downloads the document.

The issue is persistent regardless of protection status, however, I do need to maintain protection and don't want others to tamper with other object on the sheet.

Does anyone have any ideas?

Here's a snip of the code I have deployed so far:

VBA Code:
Sub PAAT_SCREENSHOT_PROPOSAL()
Sheet4.Unprotect "DHH2fanclub"
Dim fNameAndPath As Variant
Dim img As Picture
fNameAndPath = Application.GetOpenFilename(Title:="SELECT JAUMET'S AWESOMENESS")
If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
    With img
       'Resize Picture to fit in the range....
        .Left = Columns(11).Left
        .Top = Rows(2).Top
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.Height = 330#
        .ShapeRange.Width = 816#
        .ShapeRange.Rotation = 0#
        .Placement = 1
       .PrintObject = True
    End With
    Sheet4.protect "DHH2fanclub"
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
So what is the issue?
Explain what happens that you don't want to happen and when it happens.
 
Upvote 0
So, When the document is viewed by a colleague after being sent by email, internal comms app or after uploading through a TT none of the images are visible.
I can only assume that the images aren't actually embedded but are merely linked and without the images being uploaded/networked they won't be viewable.

I need the images to become part of the document itself and short of including them within a zipped folder i'm a little stuck.
 
Upvote 0
So what is the issue?
Explain what happens that you don't want to happen and when it happens.
So, When the document is viewed by a colleague after being sent by email, internal comms app or after uploading through a TT none of the images are visible.
I can only assume that the images aren't actually embedded but are merely linked and without the images being uploaded/networked they won't be viewable.

I need the images to become part of the document itself and short of including them within a zipped folder i'm a little stuck.
 
Upvote 0
I have fixed my own issue.
After playing around a little I imported as a shape instead.

Now just need to be able to define the shape parameters accordingly but it doesn't want to resize...
VBA Code:
Sub PAAT_SCREENSHOT_PROPOSAL()
Sheet4.Unprotect "DHH2fanclub"
Dim fNameAndPath As Variant
Dim img As Shape
fNameAndPath = Application.GetOpenFilename(Title:="SELECT JAUMET'S AWESOMENESS")
If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Shapes.AddPicture(Filename:=fNameAndPath, _
                                            LinkToFile:=False, SaveWithDocument:=True, _
                                            Left:=1, Top:=1, Width:=-1, Height:=-1)
    With img
       'Resize Picture to fit in the range....
        .Left = ActiveSheet.Range("K2").Left
        .Top = ActiveSheet.Range("K2").Top
        .Width = ActiveSheet.Range("K2:AA2").Width
        .Height = ActiveSheet.Range("K2:K23").Height
        .Placement = 1
        .LockAspectRatio = msoFalse
       .DrawingObject.PrintObject = True
    End With
    Sheet4.protect "DHH2fanclub"
 
Upvote 0
Solution
Move your "LockAspectRatio = msoFalse" to before the resizing. It should be the first line after "With Img".


Regarding your fixed problem. I found this also. Just good to know.

For people landing here. Different versions of Excel handle this request differently,
Excel 2007 will insert the picture as an object, ie embed it in the workbook.
Excel 2010 will insert it as a link, which is bad times if you plan on sending it to anyone.
You need to change the insert to specify that it is embedded: Insert(Filename:= <path>, LinkToFile:= False, SaveWithDocument:= True)
Exactly what you did.
 
Upvote 0
Move your "LockAspectRatio = msoFalse" to before the resizing. It should be the first line after "With Img".


Regarding your fixed problem. I found this also. Just good to know.

For people landing here. Different versions of Excel handle this request differently,
Excel 2007 will insert the picture as an object, ie embed it in the workbook.
Excel 2010 will insert it as a link, which is bad times if you plan on sending it to anyone.
You need to change the insert to specify that it is embedded: Insert(Filename:= <path>, LinkToFile:= False, SaveWithDocument:= True)
Exactly what you did.
Brilliant, such a simple fix lol.

Thanks for the help (y)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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