I'm creating an invoice template that needs to show a product image for each line item. The Invoice sheet links to a Catalog sheet using vlookup for all item data. The data for the image is a filepath, however. I need the actual photo to display on the Invoice.
I've done some digging and found the macro info below. Using this, I could theoretically use vlookup to pull in the filepath and then run the macro to pull in the image. (I could then hide the column containing the file path so that only the image shows.)
When I test run the macro, however, it's returning... Compile Error: Syntax error.
I'm very new to VBA and can't figure out where the problem is. Anyone have any thoughts or spot the issue?
Here's the info on the code.....
The below code
. loops through each cell in the selected range
. reads the filepath from that cell
. inserts the referenced picture in the cell to the right of the cell:
. resizes the height and width of the picture to the cell's height
Sub InsertPicFromFile()
Dim cCell As Range
For Each cCell In Selection
If cCell.Value <> "" Then
On Error Resume Next
ActiveSheet.Shapes.AddPicture _
Filename:=cCell.Value, LinkToFile:=msoFalse,
SaveWithDocument:=msoTrue, _
Left:=cCell.Offset(ColumnOffset:=1).Left, Top:=cCell.Top,
Width:=cCell.Height, Height:=cCell.Height
End If
Next cCell
End Sub
To use that code:
1)Select a vertical range of cells containing complete paths to picture
files.
(Make sure the row heights are large enough to view the pictures.)
2)[Alt]+[F8].....shortcut for <tools><macro><macros>....Select:
InsertPicFromFile....Click [Run]
I've done some digging and found the macro info below. Using this, I could theoretically use vlookup to pull in the filepath and then run the macro to pull in the image. (I could then hide the column containing the file path so that only the image shows.)
When I test run the macro, however, it's returning... Compile Error: Syntax error.
I'm very new to VBA and can't figure out where the problem is. Anyone have any thoughts or spot the issue?
Here's the info on the code.....
The below code
. loops through each cell in the selected range
. reads the filepath from that cell
. inserts the referenced picture in the cell to the right of the cell:
. resizes the height and width of the picture to the cell's height
Sub InsertPicFromFile()
Dim cCell As Range
For Each cCell In Selection
If cCell.Value <> "" Then
On Error Resume Next
ActiveSheet.Shapes.AddPicture _
Filename:=cCell.Value, LinkToFile:=msoFalse,
SaveWithDocument:=msoTrue, _
Left:=cCell.Offset(ColumnOffset:=1).Left, Top:=cCell.Top,
Width:=cCell.Height, Height:=cCell.Height
End If
Next cCell
End Sub
To use that code:
1)Select a vertical range of cells containing complete paths to picture
files.
(Make sure the row heights are large enough to view the pictures.)
2)[Alt]+[F8].....shortcut for <tools><macro><macros>....Select:
InsertPicFromFile....Click [Run]