insert product’s picture using vba in excel (ดึงรูปภาพสินค้าแสดงใน Excel ตาม product id)

หลายครั้ง คนที่ขอ Report จากเรา ต้องการให้ดึงข้อมูลใน Database แล้ว

ส่งเป็น File Excel กลับไป และมักจะต้องการรูปสินค้าแสดงใน Excel ด้วย

ผมได้ทำเป็น File ตัวอย่างไว้ให้ Download sample insert product picture using vba in excel

หรือทำตาม VDO ด้านล่างนี้  โดย Copy VBA ไปไว้ที่ Sheet ที่ต้องการให้แสดงรูปภาพ ซึ่ง

ตาม VDO นี้คือ Sheet1

————————VBA—————————

Dim i As Integer
Dim sFilename As String
Dim bcontinue As Boolean
Dim spath As String

Sub Attempt1()
On Error Resume Next

‘spath = “\\192.168.0.45\Picture\ProductPic\”

spath = “D:\Vdo_Capture\ProductPic\”

i = 2

bcontinue = True

While bcontinue
sFilename = Worksheets(1).Cells(i, 2).Value
If sFilename = “” Then
bcontinue = False
Else

‘Set Position Pic A = 1

Cells(i, 1).Select
ActiveSheet.Pictures.Insert(spath + sFilename + “S1.jpg”).Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = 50
Selection.ShapeRange.Width = 50
i = i + 1
End If
Wend

End Sub

—————————END———————————-

    • panu
    • February 14th, 2012

    ผมลองทำตามนี้แล้วผลออกมาไม่มีภาพแสดงครับ

  1. @panu ลองแจ้ง Error มาโดย Comment ‘On Error Resume Next มันจะแสดงว่า Error บรรทัดไหนหลังจาก Click Run VBA ครับ แต่ถ้าใช้ Excel Version 2007 อยู่ ให้ไป Download File ตัวอย่างสำหรับ Version 2007 นี้อีกทีครับ กำลังจะ Post ขึ้นไปครับ

    Ae.

  2. File Excel 2007 vba สำหรับแสดงรูปภาพใน Excel

    https://mrsakon.files.wordpress.com/2012/02/show-picture-in-excel-2007.xlsm

    Ae.

Leave a comment