Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
I have a column of file names and want to write a macro to insert th
pictures the files refer to in the cell to the right my code so far i Filename = ActiveCell.Offset(0, -1) ActiveSheet.Pictures.insert( _ "C:\Documents and Settings\12ahackett\Desktop\aspen smal pics\re sized\(filename)" ).Select the active cell being the insertion point, the variable "filename being the Jpeg filename. Any help on the correct syntax for the insert statement would b appreciate -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Dim Filename as String
Filename = ActiveCell.Offset(0, -1).Value ActiveSheet.Pictures.insert _ "C:\Documents and Settings\12ahackett\Desktop" & _ "\aspen small pics\re sized\" & Filename & ".jpg" if the cell includes the jpg extension, then you can delete that from the string above. -- Regards, Tom Ogilvy "andy hackett " wrote in message ... I have a column of file names and want to write a macro to insert the pictures the files refer to in the cell to the right my code so far is Filename = ActiveCell.Offset(0, -1) ActiveSheet.Pictures.insert( _ "C:\Documents and Settings\12ahackett\Desktop\aspen small pics\re sized\(filename)" ).Select the active cell being the insertion point, the variable "filename" being the Jpeg filename. Any help on the correct syntax for the insert statement would be appreciated --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Andy,
Here is a code that you can work with. It's for a BMP. But it may giv you some ideal. Charles Sub Get_picture() Dim fname fname = ActiveCell.Offset(0, -1) ActiveSheet.Pictures.Insert ( _ "C:\Documents and Settings\Charles Harmon\My Documents\M Pictures\") & fname<<fname wksh =101.bmp End Su -- Message posted from http://www.ExcelForum.com |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Thanks Charles. That works great. Now I have to figure a way of workin
down the column. (as you will no doubt of guessed I'm new to VBA bu enjoy learning ! -- Message posted from http://www.ExcelForum.com |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
As written, this would raise an error, even disregarding the wordwrap
problem. -- Regards, Tom Ogilvy "Charles " wrote in message ... Andy, Here is a code that you can work with. It's for a BMP. But it may give you some ideal. Charles Sub Get_picture() Dim fname fname = ActiveCell.Offset(0, -1) ActiveSheet.Pictures.Insert ( _ "C:\Documents and Settings\Charles Harmon\My Documents\My Pictures\") & fname<<fname wksh =101.bmp End Sub --- Message posted from http://www.ExcelForum.com/ |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
andy,
This assumes all bmp is in column "A"Row 1 through ?? It loops throug the colum for the bmp. Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text ActiveSheet.Pictures.Insert ( _ "C:\Documents and Settings\Charles Harmon\My Documents\M Pictures\") & fname Next End Sub Have fun. Charle -- Message posted from http://www.ExcelForum.com |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Thanks again Charles,
Unfortunately I can't get this one to work. I have put all the fil names in column A and changed the directory ref. to the correct one bu the macro stops on one the activesheet.picture.insert lin -- Message posted from http://www.ExcelForum.com |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
As written, this inserts all pictures in the activeCell, not next to the
cell with the name. -- Regards, Tom Ogilvy "Charles " wrote in message ... andy, This assumes all bmp is in column "A"Row 1 through ?? It loops through the colum for the bmp. Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text ActiveSheet.Pictures.Insert ( _ "C:\Documents and Settings\Charles Harmon\My Documents\My Pictures\") & fname Next End Sub Have fun. Charles --- Message posted from http://www.ExcelForum.com/ |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
|
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
It worked as written. It stacks all the pictures on the active cell.
-- Regards, Tom Ogilv -- Message posted from http://www.ExcelForum.com |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
|
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Charles wrote:
*Andy, Post your code and I'll look at it Charles * Code copied in below. I have all the picture ref files in column A and want the macro to ste through the column and insert the picture in each adjacent cell Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text ActiveSheet.Pictures.insert ( _ "C:\Documents and Settings\12ahackett\Desktop\aspen small pics\r sized\") & fname Next End Su -- Message posted from http://www.ExcelForum.com |
#13
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
I would assume he would the following addition:
Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text rng(i,2).Select '<== ActiveSheet.Pictures.Insert _ "C:\Documents and Settings\" _ & "Charles Harmon\My Documents\My Pictures\" _ & fname Next End Sub But if he can't get past the Pictures.Insert line, it is unclear wha his problem might be, especially if he was successful with the initia suggestion for a single cell. Just a note: () are not required around the argument to Insert since it isn' returning a value. -- Regards, Tom Ogilv -- Message posted from http://www.ExcelForum.com |
#14
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Check the path below to make sure it has spaces where they should be an
does not have spaces where they should not be. Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text rng(i,2).Select ActiveSheet.Pictures.insert _ "C:\Documents and Settings\12ahackett\" & _ "Desktop\aspen small pics\re sized\" & fname Next End Sub -- Regards, Tom Ogilvy andy hackett wrote: *Code copied in below. I have all the picture ref files in column A and want the macro t step through the column and insert the picture in each adjacent cell Sub Get_picture() Dim fname Dim rng As Range Dim i As Integer Set rng = Worksheets("sheet1").Cells(1, 1).CurrentRegion For i = 1 To rng.Rows.Count fname = rng(i, 1).Text ActiveSheet.Pictures.insert ( _ "C:\Documents and Settings\12ahackett\Desktop\aspen small pics\r sized\") & fname Next End Sub -- Message posted from http://www.ExcelForum.com |
#15
Posted to microsoft.public.excel.programming
|
|||
|
|||
using VBA to insert a column of pictures
Charles, Tom,
Thank you very much for your help and the time you have put in. The fault was mine in that I had column headers which meant the firs cell was not a picture filename. As a "newbie" I'm now working through your code to figure out how i works! It's great to have peole like yourselves who are prepared to take th time to help others out Thanks, And -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can't insert pictures | New Users to Excel | |||
Insert pictures | Excel Discussion (Misc queries) | |||
Need Help with auto insert of pictures | New Users to Excel | |||
can't insert, delete or move pictures | Excel Discussion (Misc queries) | |||
Activesheet.Pictures.Insert | Excel Programming |