INSERT PICTURE IN EXCEL USING VB6


Dear Experts,

I know it's kind of stupid but i'm really messing up with this problem..
I want to put a picture on specific range on excel. I can put the picture on the
top left of the specific range e.g range("A1")....


But my problem is that i cannot able to set the picture to TOP RIGHT of the specific cell or range...
e.g: i cannot put the picture on the top right of range "E1"...

NOTE: RANGE MAY CHANGE DEPENDING ON USERS...

I really need your help experts...

Thanks in advance...Please put me on the right direction in doing so...


game-master
LVL 13
game-masterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Jon von der HeydenConnect With a Mentor Course Leader & Managing DirectorCommented:
Could you post what you have.  See my example below:
Sub InsertPic()
 
Dim rngTarget As Range
Set rngTarget = Range("E1")
 
Const strPicPath = "C:\Documents and Settings\jon.vonderheyden\My Documents\My Pictures\Blank Female.JPG"
 
Dim dblLeft As Double
dblLeft = rngTarget.Offset(, 1).Left
 
Dim dblTop As Double
dblTop = rngTarget.Top
 
ActiveSheet.Shapes.AddPicture strPicPath, True, True, dblLeft, dblTop, 100, 100
    
End Sub

Open in new window

0
 
Rory ArchibaldConnect With a Mentor Commented:
You basically need Range F1's Left property and then subtract the width of the picture. That will give you the correct value for the Left property of your picture.
0
 
game-masterAuthor Commented:


when i run the code more than once...lets say i generate the report twice...
i got an error stating that activesheet it nothing... how do i fixed this...
0
 
Rory ArchibaldCommented:
What code are you running? If you are automating Excel from VB6 you need to fully qualify all Excel objects, so you would need something like objXL.activesheet where objXL is an Excel.Application variable
0
 
game-masterAuthor Commented:


i've got it!

i find my answer...it's working now!...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.