How could I have image URLs in column “C” display their corresponding images in column “N” in Excel?

I've an Excel file with a bunch of columns, one of which is "ImageURL", which, of course, displays unique URLs as text.

How could I set it up such that those images are also depicted within another column?

I've used the following macro, but I get a "Invalid outside procedure" compile error.

Dim url_column As Range
Dim image_column As Range

Set url_column = Worksheets(1).UsedRange.Columns("C")
Set image_column = Worksheets(1).UsedRange.Columns("N")

Dim i As Long
For i = 1 To url_column.Cells.Count

  With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
    .Left = image_column.Cells(i).Left
    .Top = image_column.Cells(i).Top
    image_column.Cells(i).EntireRow.RowHeight = .Height
  End With

Next

I am, unfortunately, new to VBA, so perhaps, I've not set it up correctly?

Answers


Ok, this may sound pretty basic (no pun intended), but based on the limited information you made available, I think that the cause of your problem is that you just pasted those statements in your code module and didn't put them inside a procedure. That will certainly give you an "Invalid outside procedure" compile-time error.

You have to put stuff inside a procedure -- either a Sub or a Function. This case calls for a Sub. Try this:

Sub PlaceImageInCell()

    Dim url_column As Range
    Dim image_column As Range
    Set url_column = Worksheets(1).UsedRange.Columns("A")
    Set image_column = Worksheets(1).UsedRange.Columns("B")

    Dim i As Long
    For i = 1 To url_column.Cells.Count
      With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
        .Left = image_column.Cells(i).Left
        .Top = image_column.Cells(i).Top
        image_column.Cells(i).EntireRow.RowHeight = .Height
      End With
    Next

End Sub

Need Your Help

Dropdown Box Inside Gridview Update Feature ASP.NET

asp.net .net gridview edit

So I have a gridview in my webpage, At the moment the table returns values from an SQL table.

Form passing null value

c# winforms

I have fixed my form load problem. I changed it to where the main menu wasn't being called on load event and that fixed the issue. Now my retrieve event gets the version but never passes it to my ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.