what have I done now... (VBA to insert images)

aelenhart

New Member
Joined
Apr 5, 2006
Messages
22
through my searching of this and other boards, I came up with the following code that would pick up the file name in E4 and insert the image in E5 and then loop through the worksheet. It works perfectly the first time, but then it seems to get stuck and repeat itself over and over with out end. obviously I am missing something.

please help!


here is the code:

Sub InsertImages()
Dim i As Integer
Dim sFilename As String
Dim bcontinue As Boolean
Dim spath As String

spath = "http://cmspro/stellent/idcplg/webdav/Contribution Folders/Exhibitions_Public/Fast Forward/FFImages/"
bcontinue = True
While bcontinue
sFilename = Worksheets(2).Cells(4, 5).Value
If sFilename = "" Then
bcontinue = False
Else
Cells(4, 6).Select
ActiveSheet.Pictures.Insert(spath + sFilename).Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 85
i = i + 1
End If
Wend
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You never change the row or column here, so it will always pick up E4.
Code:
sFilename = Worksheets(2).Cells(4, 5).Value
 
Upvote 0
Maybe use the i variable?:)

You don't seem to be doing anything else with it.
Code:
Sub InsertImages()
Dim i As Integer
Dim sFilename As String
Dim bcontinue As Boolean
Dim spath As String

    spath = "http://cmspro/stellent/idcplg/webdav/Contribution Folders/Exhibitions_Public/Fast Forward/FFImages/"
    bcontinue = True
    i = 4
    While bcontinue
        sFilename = Worksheets(2).Cells(i, 5).Value
        If sFilename = "" Then
            bcontinue = False
        Else
            Cells(i, 6).Select
            ActiveSheet.Pictures.Insert(spath + sFilename).Select
            Selection.ShapeRange.LockAspectRatio = msoTrue
            Selection.ShapeRange.Height = 85
            i = i + 1
        
        End If
    Wend
    
End Sub
 
Upvote 0
obviously that was the original idea, but when I tried I was given the 1004 error. on pressing "debug" that line comes back highlighted.
the only way I got the error to go away was by changing it to a specific cell.
I thought perhaps it was because there is nothing in column e in the first three lines of the worksheet. is is possible for me to define i as 4 to begin with and run from there?

I don't mean to seem dense, my brain is a little fried. :(
 
Upvote 0
wow. you just said that exact thing. my brain is fried. or perhaps freed.

regardless, that works perfectly until I reach the a row that does not contain an entry for the file name. ideally I would like to skip that row and continue through the worksheet until the end.
I'm sure this has something to do with the if/then part of the code.

this is what I get for trying to cheat my way through and copy someone else's code, isn't it?
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,053
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top