Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Problem with inserting picture.

I want to be able to insert a picture in a variety of cells (each cell
is a range object in the object arrayofRanges). Can someone help me
with where I am going wrong? I have a feeling I dont get the whole set
for pictures right.

Sub TestPictureInsert()

'declarations
Dim picQCAnormal As Picture
Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")
Dim pic As Picture

'Put a picture the size of each range in each range _
(each range is only one cell)

For each rnge in arrayofRanges
Set pic = picQCAnormal
With pic
.Top = rnge.Top
.Left = rnge.Width
.Width = rnge.Width
.Height = rnge.Height
End With
Next rnge

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem with inserting picture.

You're only inserting one picture, then moving it to each cell in that range--so
only the last cell in that range has the picture when you're done.

You could import the picture multiple times or import it once and copy it lots
of times.

Option Explicit
Sub TestPictureInsert()

'declarations
Dim ArrayOfRanges As Range
Dim rnge As Range
Dim picQCAnormal As Picture
Dim pic As Picture

'for my testing
With Worksheets(2)
Set ArrayOfRanges = .Range("a1,c3,e5,g7")
End With

Set picQCAnormal = Worksheets(2).Pictures.Insert("C:\oneCell_normal.b mp")

For Each rnge In ArrayOfRanges.Cells
With rnge.Parent 'worksheets(2)
picQCAnormal.Copy
.Paste
Set pic = .Pictures(.Pictures.Count) 'the one just pasted
End With
With pic
.Top = rnge.Top
.Left = rnge.Left
.Width = rnge.Width
.Height = rnge.Height
.Name = "Pic_" & rnge.Address(0, 0)
End With
Next rnge

'clean up the "master picture"
picQCAnormal.Delete

End Sub

And watch your typing. Worksheets(2), not worksheet(2)

Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")

And I bet you didn't mean this:
.Left = rnge.Width
(left = width???)


" wrote:

I want to be able to insert a picture in a variety of cells (each cell
is a range object in the object arrayofRanges). Can someone help me
with where I am going wrong? I have a feeling I dont get the whole set
for pictures right.

Sub TestPictureInsert()

'declarations
Dim picQCAnormal As Picture
Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")
Dim pic As Picture

'Put a picture the size of each range in each range _
(each range is only one cell)

For each rnge in arrayofRanges
Set pic = picQCAnormal
With pic
.Top = rnge.Top
.Left = rnge.Width
.Width = rnge.Width
.Height = rnge.Height
End With
Next rnge

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Problem with inserting picture.

Thanks Dave, worked perfectly. My typing was a bit sloppy, thanks for
catching that.

Another question, if you happen to know, can one set the transparent
color for the imported picture? Also, if I wanted to make the workbook
that this code is a part of into an add-in, how would I keep the
picture with it?

Thanks again,

-Abe

Dave Peterson wrote:
You're only inserting one picture, then moving it to each cell in that range--so
only the last cell in that range has the picture when you're done.

You could import the picture multiple times or import it once and copy it lots
of times.

Option Explicit
Sub TestPictureInsert()

'declarations
Dim ArrayOfRanges As Range
Dim rnge As Range
Dim picQCAnormal As Picture
Dim pic As Picture

'for my testing
With Worksheets(2)
Set ArrayOfRanges = .Range("a1,c3,e5,g7")
End With

Set picQCAnormal = Worksheets(2).Pictures.Insert("C:\oneCell_normal.b mp")

For Each rnge In ArrayOfRanges.Cells
With rnge.Parent 'worksheets(2)
picQCAnormal.Copy
.Paste
Set pic = .Pictures(.Pictures.Count) 'the one just pasted
End With
With pic
.Top = rnge.Top
.Left = rnge.Left
.Width = rnge.Width
.Height = rnge.Height
.Name = "Pic_" & rnge.Address(0, 0)
End With
Next rnge

'clean up the "master picture"
picQCAnormal.Delete

End Sub

And watch your typing. Worksheets(2), not worksheet(2)

Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")

And I bet you didn't mean this:
.Left = rnge.Width
(left = width???)


" wrote:

I want to be able to insert a picture in a variety of cells (each cell
is a range object in the object arrayofRanges). Can someone help me
with where I am going wrong? I have a feeling I dont get the whole set
for pictures right.

Sub TestPictureInsert()

'declarations
Dim picQCAnormal As Picture
Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")
Dim pic As Picture

'Put a picture the size of each range in each range _
(each range is only one cell)

For each rnge in arrayofRanges
Set pic = picQCAnormal
With pic
.Top = rnge.Top
.Left = rnge.Width
.Width = rnge.Width
.Height = rnge.Height
End With
Next rnge

End Sub


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem with inserting picture.

If you rightclick on the picture, you can choose format picture.

Then experiment with the Fill|color|transparency settings.

(I've never had good luck with that, though.)

Put the picture on one of the sheets in the addin.

Copy it from there.

And still paste it into the worksheet you want.

Set picQCAnormal _
= thisworkbook.Worksheets("pictureSheet").Pictures(" PictNameHere")



" wrote:

Thanks Dave, worked perfectly. My typing was a bit sloppy, thanks for
catching that.

Another question, if you happen to know, can one set the transparent
color for the imported picture? Also, if I wanted to make the workbook
that this code is a part of into an add-in, how would I keep the
picture with it?

Thanks again,

-Abe

Dave Peterson wrote:
You're only inserting one picture, then moving it to each cell in that range--so
only the last cell in that range has the picture when you're done.

You could import the picture multiple times or import it once and copy it lots
of times.

Option Explicit
Sub TestPictureInsert()

'declarations
Dim ArrayOfRanges As Range
Dim rnge As Range
Dim picQCAnormal As Picture
Dim pic As Picture

'for my testing
With Worksheets(2)
Set ArrayOfRanges = .Range("a1,c3,e5,g7")
End With

Set picQCAnormal = Worksheets(2).Pictures.Insert("C:\oneCell_normal.b mp")

For Each rnge In ArrayOfRanges.Cells
With rnge.Parent 'worksheets(2)
picQCAnormal.Copy
.Paste
Set pic = .Pictures(.Pictures.Count) 'the one just pasted
End With
With pic
.Top = rnge.Top
.Left = rnge.Left
.Width = rnge.Width
.Height = rnge.Height
.Name = "Pic_" & rnge.Address(0, 0)
End With
Next rnge

'clean up the "master picture"
picQCAnormal.Delete

End Sub

And watch your typing. Worksheets(2), not worksheet(2)

Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")

And I bet you didn't mean this:
.Left = rnge.Width
(left = width???)


" wrote:

I want to be able to insert a picture in a variety of cells (each cell
is a range object in the object arrayofRanges). Can someone help me
with where I am going wrong? I have a feeling I dont get the whole set
for pictures right.

Sub TestPictureInsert()

'declarations
Dim picQCAnormal As Picture
Set picQCAnormal = _
Worksheet(2).Pictures.Insert("C:\oneCell_normal.bm p")
Dim pic As Picture

'Put a picture the size of each range in each range _
(each range is only one cell)

For each rnge in arrayofRanges
Set pic = picQCAnormal
With pic
.Top = rnge.Top
.Left = rnge.Width
.Width = rnge.Width
.Height = rnge.Height
End With
Next rnge

End Sub


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting a Picture using Cell as picture name. the-jackal Links and Linking in Excel 12 November 10th 08 09:21 AM
Problem inserting a picture and getting it to go behind the data markmcd Excel Discussion (Misc queries) 0 November 30th 07 02:11 AM
Problem inserting a picture in Excel that ONLY shows when clicked Blackgammon Excel Discussion (Misc queries) 3 March 31st 06 07:11 PM
Very strange problem when inserting a picture in a 3D Chart DDearborn Charts and Charting in Excel 0 January 5th 06 05:36 PM
get a picture width and height without inserting the picture Dorothy Excel Programming 1 January 13th 05 05:06 AM


All times are GMT +1. The time now is 08:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"