UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Insert Image Into Cell With VBA (need To Tweak), Office 2013    
 
   
jimbofoxman
post Apr 19 2017, 04:03 PM
Post#1



Posts: 302
Joined: 4-April 08



I'm not familiar with coding in Excel, so I am kinda lost. I found this code which works great, but I would like to tweak it a bit. I would like to instead of selecting the cell, have it automatically put it in two designated cells. Cells A18 and L18.

CODE
Sub piccy()
Dim sFile As Variant, r As Range
sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
If sFile = False Then Exit Sub
On Error Resume Next
Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
If r.Count > 1 Then Exit Sub
ActiveSheet.Pictures.Insert (sFile)
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
    .LockAspectRatio = True
    .Top = r.Top
    .Left = r.Left
    .Height = r.RowHeight * r.MergeArea.Rows.Count
End With
End Sub


Can anyone assist me with inserting the image in to the same 2 cells everytime the button is clicked?

Thank you

Jim
Go to the top of the page
 
theDBguy
post Apr 19 2017, 04:21 PM
Post#2


Access Wiki and Forums Moderator
Posts: 70,413
Joined: 19-June 07
From: SunnySandyEggo


Hi Jim,

Try replacing the InputBox line with something like:

Set r = ActiveSheet.Range("A18")

(untested)
Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
jimbofoxman
post Apr 20 2017, 07:08 AM
Post#3



Posts: 302
Joined: 4-April 08



That worked, thank you.
Go to the top of the page
 
theDBguy
post Apr 20 2017, 07:24 AM
Post#4


Access Wiki and Forums Moderator
Posts: 70,413
Joined: 19-June 07
From: SunnySandyEggo


You're welcome. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd August 2017 - 02:29 PM