please guide me how to insert a picture to a particular cell in excel sheet?

I used the following code, but it inserts the picture in the excel file not in the cell I specified.


Dim xApp As Object
Dim xWb As Object
Dim xWs As Object
Dim img as string
Set xApp = CreateObject("Excel.Application")
xApp.Workbooks.Open (filename)
xApp.Visible = True
img = .filename
Picture1.Picture = LoadPicture(img)

xApp.Workbooks.Add
Set xWb = xApp.Workbooks(1)
Set xWs = xWb.Worksheets(1)
xWs.range("B5").Select

xApp.activesheet.Pictures.Insert(img).Select

I dont think yopu can insert a picture into a cell the best you can do is lock it to a cell and set the move and resize property for the picture

Try the following at the end of your code

With Selection
        .Placement = xlMoveAndSize
        .PrintObject = True
    End With

If you have formated the cell to the right size before insertion then it should look like its been inserted.

Other placement options xlMove - moves with cell but does not resize or xlFreeFloating - no resize or move.

Hope that helps.

Graham

please guide me how to insert a picture to a particular cell in excel sheet?

I used the following code, but it inserts the picture in the excel file not in the cell I specified.


Dim xApp As Object
Dim xWb As Object
Dim xWs As Object
Dim img as string
Set xApp = CreateObject("Excel.Application")
xApp.Workbooks.Open (filename)
xApp.Visible = True
img = .filename
Picture1.Picture = LoadPicture(img)

xApp.Workbooks.Add
Set xWb = xApp.Workbooks(1)
Set xWs = xWb.Worksheets(1)
xWs.range("B5").Select

xApp.activesheet.Pictures.Insert(img).Select

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.