Get Imahes From a range

crazyeyeschase

Board Regular
Joined
May 6, 2014
Messages
104
Office Version
  1. 365
Platform
  1. Windows
I am wanting to copy a range of images from one WB to another.

I am going to try to explain this as best as i can .

WB1 for example is the WB with the images and WB2 is where the images need to be copied to.

Inside of WB2 i have the Cells set so A1:A6 contain the Picture name and B1:B6 is where i want the pictures copied.

Example:
example_zps98207d58.png


Inside WB1 is the exact same setup but it included the images

Example:
example2_zps785df1d2.png


This is the Code i have came up with to get at least one image to be copied
Code:
Sub GetPics()
Dim PicRange As Range
Dim PicName As String
Set PicRange = Range("A1")
PicName = PicRange

Application.ScreenUpdating = False
Application.Workbooks.Open (ThisWorkbook.Path & _
     Application.PathSeparator & "Test2.xlsm")


    Sheets("Pictures").Select
    ActiveSheet.Shapes.Range(Array(PicName)).Select
    Selection.Copy
    Windows("Test1.xlsm").Activate
    Range("B1").Select
    ActiveSheet.Paste
    
    MsgBox "IMG Copied"

     
Workbooks("Test2.xlsm").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.ScreenUpdating = True
End Sub

This works fine however i am wanting the macro to get the value/text from each cell in A1:A6 and use that value as the picture name and then paste each picture in the correct position from B1:b6.

I am sorry if i didnt explain this good enough. This is just a test swatch when/if i get this figured out it will be for a much larger project.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I have
B3:B4 merged
B5:B6 merged

and the same with column C and D so their is actualey only 6 Cells

Its not being used for the same code just trying to manipulate things and figure out how i can do it. I have dont a bit of searching and checked some of my other codes but since the images behave differently then normal cells its a little more confusing for myself.

If you can adjust the first code to work with these 6 (merged) cells i am sure i can play around and figure it out.
 
Upvote 0
VBA and merged cells don't get on, but try:

Code:
Sub GetPics()
    Dim wb As Workbook
    Dim PicRange As Range
    Dim PicName As String
    Dim Cell As Range
    Dim r As Long
    Dim c As Long
    Set PicRange = Range("A1:A6")
    Application.ScreenUpdating = False
    Set wb = Application.Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & "Test2.xlsm")
    ThisWorkbook.Activate
    r = 3
    c = 2
    For Each Cell In PicRange
        PicName = Cell.Value
        wb.Sheets("Pictures").Shapes(PicName).Copy
        Cells(r, c).Select
        If r = 3 Then
            r = r + 2
        Else
            r = 3
            c = c + 1
        End If
        ActiveSheet.Paste
    Next Cell
    MsgBox "IMG Copied"
    wb.Close SaveChanges:=True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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