ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   inserting pictures (https://www.excelbanter.com/excel-programming/424631-inserting-pictures.html)

Brad

inserting pictures
 
I need to write some code that will insert 8 pictures on 8 different sheets.
I will also need the ability to go back and delete any pictures that are on
the sheet. I'm having some problems with the code to insert the pictures,
here is what i've got any help will be appreciated

' delete
for i = 1 to 8
Sheets("Sheet" & i).Activate
photo(i).picture.Delete
next

' insert
dim photo(1 to 8) as image
dim picLocation as string
dim iCount as integer

for iCount = 1 to 8
picLocation = "C:\Pic" & iCount & ".jpg"
Sheets("Sheet" & iCount).Activate
Range("D6").Select
set photo(iCount) = activesheet.pictures.insert(picLocation)
photo(a).picture.width = 2
photo(a).picture.height = 3
next



joel

inserting pictures
 
Your Dim statement is wrong

from
dim photo(1 to 8) as image

to
dim photo(8) as image

"Brad" wrote:

I need to write some code that will insert 8 pictures on 8 different sheets.
I will also need the ability to go back and delete any pictures that are on
the sheet. I'm having some problems with the code to insert the pictures,
here is what i've got any help will be appreciated

' delete
for i = 1 to 8
Sheets("Sheet" & i).Activate
photo(i).picture.Delete
next

' insert
dim photo(1 to 8) as image
dim picLocation as string
dim iCount as integer

for iCount = 1 to 8
picLocation = "C:\Pic" & iCount & ".jpg"
Sheets("Sheet" & iCount).Activate
Range("D6").Select
set photo(iCount) = activesheet.pictures.insert(picLocation)
photo(a).picture.width = 2
photo(a).picture.height = 3
next



Dave Peterson

inserting pictures
 

'delete all the pictures on Sheet1 to Sheet8
dim iCtr as long
for ictr = 1 to 8
sheets("sheet" & ictr).pictures.delete
next ictr


'insert a single picture on 8 different sheets
dim iCtr as long
dim myPict as Picture
for ictr = 1 to 8
with sheets("sheet" & ictr)
set mypict = .pictures.insert("C:\Pic" & ictr & ".jpg")
with .range("D2") 'place the picture over D2????
myPict.Top = .Top
myPict.Left = .Left
myPict.Width = .Width
myPict.Height = .Height
end with
end with
next ictr




Brad wrote:

I need to write some code that will insert 8 pictures on 8 different sheets.
I will also need the ability to go back and delete any pictures that are on
the sheet. I'm having some problems with the code to insert the pictures,
here is what i've got any help will be appreciated

' delete
for i = 1 to 8
Sheets("Sheet" & i).Activate
photo(i).picture.Delete
next

' insert
dim photo(1 to 8) as image
dim picLocation as string
dim iCount as integer

for iCount = 1 to 8
picLocation = "C:\Pic" & iCount & ".jpg"
Sheets("Sheet" & iCount).Activate
Range("D6").Select
set photo(iCount) = activesheet.pictures.insert(picLocation)
photo(a).picture.width = 2
photo(a).picture.height = 3
next


--

Dave Peterson


All times are GMT +1. The time now is 11:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com