วันเสาร์ที่ 18 พฤศจิกายน พ.ศ. 2560

การใส่รูปภาพเข้าไปใน cell ของ Excell 2016

เราจะใส่รูปลงใน cell ใดๆ ให้ตรงกับชื่อของนักเรียน
ขั้นตอนการทำงานของวิธีนี้ มีดังนี้
1.เปิดโปรแกรม Excel ขึ้นมา กำหนด A1 ใส่ชื่อ  B1ใส่รูป
2. คลิ้กที่แท็บ Developer หรือ "นักพัฒนา"  หากหาเมนู Developer ไม่เจอให้ไปที่ File --> Option
3.เลือกปุ่ม command button มา 1 ตัว




    แล้ววาดลงตรงตำแหน่งที่ต้องการ จะปรากฎกล่อง Assign Macro ขึ้นมา
    1) ตรงช่อง Macro name ให้ตั้งชื่อ macro
    2) Macros in ให้เลือกว่าจะใช้ได้กับ sheet or work book ใดได้บ้าง
    3) กดปุ่ม New
    4) กดปุ่ม OK
     จากนั้นจะปรากฎกล่อง VB ขึ้นมา ให้คัดลอกคำสั่งไปใส่

Dim sPicture As String, pic As Picture

sPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
, "please select picture as you want")

If sPicture = "False" Then Exit Sub

Set pic = ActiveSheet.Pictures.Insert(sPicture)
With pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Placement = xlMoveAndSize
End With

Set pic = Nothing

   แล้วปิดหน้า VB

4.จากนั้นให้เราคลิ้กที่ เซลล์ B2 ที่ต้องการให้ภาพเข้าไปอยู่ แล้ว คลิ้กที่ Button 1 หนึ่งครั้ง จะปรากฎกล่องค้นหารูป ทำการค้นหาตำแหน่งที่รูปเก็บอยู่ คลิกเลือกรูป แล้วกด open รูปก็จะมาอยู่ในเซลล์ที่เราเลือกไว้




อ้างอิง
http://vba-msexcell.blogspot.com/2014/07/excel-cell.html
https://kvichian.wordpress.com/2011/03/15/แทรกรูปภาพใน-cell-ให้พอดีกั/
http://it-centerpoint.com/?name=news&file=readnews&id=57#sthash.bpfb64PQ.dpbs