Hi Gav,
Select one of the cells and run the code. This will insert the image for
that heading. Select the next setting and run the code again. Continue for
all additional headings. If your headings will always be located in the same
cells you could run the code inside a loop that iterates through all of
those cells
--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/
* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
"Gav" wrote in message
...
Gday rob,
How do i run this code?? Does will it insert images in the cell beneath my
headings?? There are 5 headings in total and each heading may have a
correpsonding image.
Cheers!!!!!
----- Rob Bovey wrote: -----
Hi Gav,
I've made a modification to the code (shown below) that causes
the top
left corner of the specified picture to be positioned in the top left
corner
of the cell directly below the current selection. So if the user
selects the
header cell prior to running the macro it should do what you want.
Private Const S_OK As Long = 0
Private Const SHGFP_TYPE_CURRENT As Long = 0
Private Const CSIDL_PERSONAL As Long = 5
Private Const MAX_PATH As Long = 256
Private Declare Function SHGetFolderPathA Lib "Shell32.dll" _
(ByVal hWndOwner As Long, _
ByVal nFolder As Long, _
ByVal hToken As Long, _
ByVal dwFlags As Long, _
ByVal szPath As String) As Long
Public Sub InsertImageBelowRange()
Dim objImage As Picture
Dim rngCell As Range
Dim szPath As String
Dim vFullName As Variant
Set rngCell = Selection.Offset(1, 0)
szPath = szGetMyDocsPath() & "\"
If Len(szPath) 0 Then
ChDrive szPath
ChDir szPath
vFullName = Application.GetOpenFilename( _
"Image Files (*.jpg),*.jpg", , "Select an Image")
If vFullName < False Then
Set objImage = Sheet1.Pictures.Insert(CStr(vFullName))
objImage.Top = rngCell.Top
objImage.Left = rngCell.Left
End If
Else
MsgBox "My Documents folder not found."
End If
End Sub
Private Function szGetMyDocsPath() As String
Dim szPath As String
szPath = String$(MAX_PATH, vbNullChar)
If SHGetFolderPathA(0&, CSIDL_PERSONAL, 0&, SHGFP_TYPE_CURRENT, _
szPath) = S_OK
Then
szGetMyDocsPath = Left$(szPath, InStr(szPath, vbNullChar))
End If
End Function
--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/
* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
"Gav" wrote in message
...
thanks again bob....before i go any further, i have a query......to
ditermine where the image pastes, can i use a heading???
IE: the sheet has certain sub headings like 'machine' and
'roller'. Can i
use these headings as the targets in some way. I would like the image
to
paste into the empty cell beneath the heading. For each heading, the
user
would select an image.
Thanks!!!!!!