Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

INSERT PICTURE IN EXCEL USING VB6

Posted on 2009-05-12
5
1,159 Views
Last Modified: 2012-05-06

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
0
Comment
Question by:game-master
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Jon von der Heyden earned 250 total points
ID: 24363430
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
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 250 total points
ID: 24363618
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
 
LVL 13

Author Comment

by:game-master
ID: 24371056


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
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24371686
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
 
LVL 13

Author Comment

by:game-master
ID: 24371909


i've got it!

i find my answer...it's working now!...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question