Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Help with importing pictures from hyperlinks

I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help with importing pictures from hyperlinks


Sub test()

For Each cell In Columns("C")
PictName = cell.Hyperlinks.Item(1).Name
If PictName < "" Then
ActiveSheet.Pictures.Insert Filename:=PictName
End If
Next cell

End Sub

"forxigan" wrote:

I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Help with importing pictures from hyperlinks

hi and thanks for the response.

I'm not much familiar with VB and i'm getting and error while running the
macro: "Run-time error '1004' - Insert method of Picture class failed"
the highlighted line in the debugger is:
ActiveSheet.Pictures.Insert Filename:=PictName

Could you please suggest what i'm doing wrong here?
Thanks in advance.

"Joel" wrote:


Sub test()

For Each cell In Columns("C")
PictName = cell.Hyperlinks.Item(1).Name
If PictName < "" Then
ActiveSheet.Pictures.Insert Filename:=PictName
End If
Next cell

End Sub

"forxigan" wrote:

I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help with importing pictures from hyperlinks


Sub test()

For Each cell In Columns("C")
PictName = cell.Hyperlinks.Item(1).Name
If PictName < "" Then
ActiveSheet.Pictures.Insert Filename:=PictName
End If
Next cell

End Sub

"forxigan" wrote:

I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,118
Default Help with importing pictures from hyperlinks

If you'd consider putting the hyperlinked pictures in the cells' comments,
then putting the mouse pointer over the cell would display the associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select: ConvertLinksToCommentPics...Click: Run

The hyperlinks will be removed and the linked pictures will be inserted into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Help with importing pictures from hyperlinks

hi,

First of all thanks for the quick response.
This solution could definitely work for me, tho, seeing all the product pics
at once could have some advantages as well.

The problem is, i'm not much familiar with VB and i'm getting an error
window after running the macro:
"Run-time error '-2147024809 (800070057)':
the item with specified name wasn't found."

the line which highlights in the debugger is: With
ActiveSheet.Shapes("TempPic")

Something does happen tho: the hyperlink of the first cell out of several
selected is being converted to text(hyperlink name) and comment is being
added to the cell, but it's blank.


"Ron Coderre" wrote:

If you'd consider putting the hyperlinked pictures in the cells' comments,
then putting the mouse pointer over the cell would display the associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select: ConvertLinksToCommentPics...Click: Run

The hyperlinks will be removed and the linked pictures will be inserted into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.





  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,118
Default Help with importing pictures from hyperlinks

Hmmmm.....Using an empy workbook, I created some hyperlinks and followed the
instructions I posted. The macro ran without incident and the pictures were
displayed in comment boxes.

I'm guessing the issue lies with the links.
Are they created using <insert<hyperlink?
What kinds of pictures do they link to? (jpeg, bmp, gif, something else)

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"forxigan" wrote in message
...
hi,

First of all thanks for the quick response.
This solution could definitely work for me, tho, seeing all the product
pics
at once could have some advantages as well.

The problem is, i'm not much familiar with VB and i'm getting an error
window after running the macro:
"Run-time error '-2147024809 (800070057)':
the item with specified name wasn't found."

the line which highlights in the debugger is: With
ActiveSheet.Shapes("TempPic")

Something does happen tho: the hyperlink of the first cell out of several
selected is being converted to text(hyperlink name) and comment is being
added to the cell, but it's blank.


"Ron Coderre" wrote:

If you'd consider putting the hyperlinked pictures in the cells'
comments,
then putting the mouse pointer over the cell would display the associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select: ConvertLinksToCommentPics...Click:
Run

The hyperlinks will be removed and the linked pictures will be inserted
into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the
rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to
my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.








  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Help with importing pictures from hyperlinks

hi,

You were absolutely right - the problem were in the hyperlinks.
I tried to create a few links myself and the macro worked perfectly, thx.
The original workbook wasn't made by me, so no idea how the hyperlinks were
created there.

Is there an option to auto rebuild them somehow, as we're talking about
thousands of links here?

And another question: could you think of the way to show all the pics in the
workbook and not as cell comments, because i'm not sure the comments solution
will 100% work for me, tho it's still very helpful, thanks.
I know you can't attach a picture into a cell, but they all have the same
width, so i could simply set rows size accordingly, so they would fit in.

Thanks in advance.

"Ron Coderre" wrote:

Hmmmm.....Using an empy workbook, I created some hyperlinks and followed the
instructions I posted. The macro ran without incident and the pictures were
displayed in comment boxes.

I'm guessing the issue lies with the links.
Are they created using <insert<hyperlink?
What kinds of pictures do they link to? (jpeg, bmp, gif, something else)

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"forxigan" wrote in message
...
hi,

First of all thanks for the quick response.
This solution could definitely work for me, tho, seeing all the product
pics
at once could have some advantages as well.

The problem is, i'm not much familiar with VB and i'm getting an error
window after running the macro:
"Run-time error '-2147024809 (800070057)':
the item with specified name wasn't found."

the line which highlights in the debugger is: With
ActiveSheet.Shapes("TempPic")

Something does happen tho: the hyperlink of the first cell out of several
selected is being converted to text(hyperlink name) and comment is being
added to the cell, but it's blank.


"Ron Coderre" wrote:

If you'd consider putting the hyperlinked pictures in the cells'
comments,
then putting the mouse pointer over the cell would display the associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select: ConvertLinksToCommentPics...Click:
Run

The hyperlinks will be removed and the linked pictures will be inserted
into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the
rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to
my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.








  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,118
Default Help with importing pictures from hyperlinks

Rebuild them?...Maybe.

Can you post what you know about them?
Is it a Hyperlink formula? and not a Hyperlink?

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
hi,

You were absolutely right - the problem were in the hyperlinks.
I tried to create a few links myself and the macro worked perfectly, thx.
The original workbook wasn't made by me, so no idea how the hyperlinks
were
created there.

Is there an option to auto rebuild them somehow, as we're talking about
thousands of links here?

And another question: could you think of the way to show all the pics in
the
workbook and not as cell comments, because i'm not sure the comments
solution
will 100% work for me, tho it's still very helpful, thanks.
I know you can't attach a picture into a cell, but they all have the same
width, so i could simply set rows size accordingly, so they would fit in.

Thanks in advance.

"Ron Coderre" wrote:

Hmmmm.....Using an empy workbook, I created some hyperlinks and followed
the
instructions I posted. The macro ran without incident and the pictures
were
displayed in comment boxes.

I'm guessing the issue lies with the links.
Are they created using <insert<hyperlink?
What kinds of pictures do they link to? (jpeg, bmp, gif, something else)

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"forxigan" wrote in message
...
hi,

First of all thanks for the quick response.
This solution could definitely work for me, tho, seeing all the product
pics
at once could have some advantages as well.

The problem is, i'm not much familiar with VB and i'm getting an error
window after running the macro:
"Run-time error '-2147024809 (800070057)':
the item with specified name wasn't found."

the line which highlights in the debugger is: With
ActiveSheet.Shapes("TempPic")

Something does happen tho: the hyperlink of the first cell out of
several
selected is being converted to text(hyperlink name) and comment is
being
added to the cell, but it's blank.


"Ron Coderre" wrote:

If you'd consider putting the hyperlinked pictures in the cells'
comments,
then putting the mouse pointer over the cell would display the
associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select:
ConvertLinksToCommentPics...Click:
Run

The hyperlinks will be removed and the linked pictures will be
inserted
into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions
from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the
rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website
to
my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.










  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Help with importing pictures from hyperlinks

hi,

You were absolutely right - the problem were in the hyperlinks.
I tried to create a few links myself and the macro worked perfectly, thx.
The original workbook wasn't made by me, so no idea how the hyperlinks were
created there.

Is there an option to auto rebuild them somehow, as we're talking about
thousands of links here?

And another question: could you think of the way to show all the pics in the
workbook and not as cell comments, because i'm not sure the comments solution
will 100% work for me, tho it's still very helpful, thanks.
I know you can't attach a picture into a cell, but they all have the same
width, so i could simply set rows size accordingly, so they would fit in.

Thanks in advance.


"Ron Coderre" wrote:

Hmmmm.....Using an empy workbook, I created some hyperlinks and followed the
instructions I posted. The macro ran without incident and the pictures were
displayed in comment boxes.

I'm guessing the issue lies with the links.
Are they created using <insert<hyperlink?
What kinds of pictures do they link to? (jpeg, bmp, gif, something else)

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"forxigan" wrote in message
...
hi,

First of all thanks for the quick response.
This solution could definitely work for me, tho, seeing all the product
pics
at once could have some advantages as well.

The problem is, i'm not much familiar with VB and i'm getting an error
window after running the macro:
"Run-time error '-2147024809 (800070057)':
the item with specified name wasn't found."

the line which highlights in the debugger is: With
ActiveSheet.Shapes("TempPic")

Something does happen tho: the hyperlink of the first cell out of several
selected is being converted to text(hyperlink name) and comment is being
added to the cell, but it's blank.


"Ron Coderre" wrote:

If you'd consider putting the hyperlinked pictures in the cells'
comments,
then putting the mouse pointer over the cell would display the associated
picture.

Here's how:

First, add the below procedures to a General Module
(Watch out for text wrap issues)

To run the macros....
1) Select the range of hyperlink cells that reference pictures
2) Run the "ConvertLinksToCommentPics" macro
<tools<macro<macros.....Select: ConvertLinksToCommentPics...Click:
Run

The hyperlinks will be removed and the linked pictures will be inserted
into
the cells comments.


Sub ConvertLinksToCommentPics()
Dim cCell As Range
Dim rngSelection As Range
Dim strHLink As String
Dim cComment As Comment

Dim iNewHgt As Integer
Dim iNewWidth As Integer

For Each cCell In Selection
If cCell.Hyperlinks.Count 0 Then
'The cell contains a hyperlink
With cCell
'Store the hyperlink target
strHLink = .Hyperlinks(1).Address

If strHLink < "" Then
.Hyperlinks(1).Delete

'If the cell doesn not contain a comment create one
Set cComment = .Comment
If cComment Is Nothing Then
Set cComment = .AddComment(Text:="")
End If

'Build a temporary picture shape to read dimensions from
'then delete the shape containing the picture
InsertPicFromFile _
strFileLoc:=strHLink, _
rDestCells:=[A1], _
blnFitInDestHeight:=False, _
strPicName:="TempPic"

With ActiveSheet.Shapes("TempPic")
iNewHgt = .Height
iNewWidth = .Width
End With

ActiveSheet.Shapes("TempPic").Delete

'Alter the comment to use the picture as the Fill
'and size the shape to the original picture size
With cComment.Shape
.Fill.UserPicture PictureFile:=strHLink
.LockAspectRatio = msoFalse
.Height = iNewHgt
.Width = iNewWidth
End With
End If
End With
End If
Next cCell
End Sub

'******************************
'* InserPicFromFile *
'* Programmer: Ron Coderre *
'* Last Update: 20-SEP-2007 *
'******************************
Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the
rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, _
Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

If blnFitInDestHeight = True Then
'Resize the picture to fit in the destination cells
oNewPic.Height = .Height - 1
End If

'Assign the desired name to the picture
oNewPic.Name = strPicName
End With 'rCellDest
End Sub


Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"forxigan" wrote in message
...
I have an excel table which contains a list of products.
One of the columns contains a list of hyperlinks to each product's
picture,
on a certain website.
I need a solution to get/import the actual pictures from the website to
my
table, according to each product's hyperlink(i can translate each
hyperlink
into a cell with the web adress of the picture, if it helps).

Thanks in advance.










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
Help opening pictures from hyperlinks BC From KY Excel Discussion (Misc queries) 0 February 11th 08 02:19 AM
Viewing Pictures in Hyperlinks DaddyO Excel Discussion (Misc queries) 0 December 4th 07 06:09 PM
Replace hyperlinks with actual pictures mi Links and Linking in Excel 2 May 30th 06 07:50 PM
importing pictures sumera usman New Users to Excel 2 November 27th 05 06:49 PM
Importing pictures and re scaling ChrisP Excel Discussion (Misc queries) 1 October 18th 05 02:10 PM


All times are GMT +1. The time now is 04:30 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"