Solved

INSERT PICTURE IN EXCEL USING VB6

Posted on 2009-05-12
5
1,155 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now