Auto_Open image Macro

DWatPerry

New Member
Joined
Jan 16, 2012
Messages
8
Hi,

I am new to all this Macro stuff, and I am really struggling with trying to get excel to open an image automatically and insert it into a particular place.

I am using a program called Driveworks to create the excel sheet and it creates a link in a specified cell called "Jpeg" which is the file location.

I need the file name in the cell called "Jpeg" (*example* C\:file location\image1.jpeg) to open that image and insert it into either the named cell range ImageRange or Width X7:Z7 height X7:X28

The reason that the file name has to read off of the cell is because every time Driveworks is run different specifications are produced and a 2D image is created after each specification is complete, there-fore every new file is going to be different to the last file.

As the sheet is a specification sheet it has a set A4 format that the image has to fit into (hence the ranges)

I have tried adapting all sorts of Macro's that I have found on here and all over the internet, but the truth of it is.... I just don't get it! if there is anyone out there who can help even the slightest bit I would be forever grateful!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here is my take on what you want.

Code:
Sub ShowPictue()
    ActiveSheet.Pictures.Insert(Range("Jpeg")).Select
    With Selection
        .Left = Range("X7").Left
        .Top = Range("X7").Top
        .Width = Range("Z7").Left - Range("X7").Left + Range("Z7").Width
        .Height = Range("x28").Top - Range("x7").Top
    End With
End Sub
 
Upvote 0
Turns out the "Select" is not required.

Code:
Sub ShowPictue()
    With ActiveSheet.Pictures.Insert(Range("Jpeg"))
        .Left = Range("X7").Left
        .Top = Range("X7").Top
        .Width = Range("Z7").Left - Range("X7").Left + Range("Z7").Width
        .Height = Range("x28").Top - Range("x7").Top
    End With
End Sub
 
Upvote 0
One last time:

Code:
Sub ShowPictue()
    With ActiveSheet.Pictures.Insert(Range("Jpeg"))
        .Left = Range("X7:z28").Left
        .Top = Range("X7:z28").Top
        .Width = Range("X7:z28").Width
        .Height = Range("X7:Z28").Height
    End With
End Sub
 
Upvote 0
thanks for the help, but when I run that macro excel crashes. It doesn't like running macros for some reason, it has done it to me with other Macros I have tried. Any thoughts on why it is crashing on me?
 
Upvote 0
I Have got this working without crashing, and it seems to work... anyone know anything about writing Macros to open photoshop and edit images? lol.

thanks for all the help!



Sub test()


Dim picture As Object
Dim address As String
Dim x As Integer
Dim y As Integer
Dim a As Integer
Dim b As Integer

address = Range("JPEG")
x = Range("X7:Z7").Width
y = Range("X7:X72").Height




Range("AA7").Select

With ActiveSheet.Pictures.Insert(address)

.Left = Range("X7:z78").Left
.Top = Range("X7:z78").Top
.Width = Range("X7:z78").Width
.Height = Range("X7:Z78").Height
End With
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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