ซ่อมคอมพิวเตอร์นอกสถานที่ รามตำแหง บางกะปิ 083-792-5426

วันพุธที่ 18 กรกฎาคม พ.ศ. 2555

Microsoft Excel Tips and Tricks: เทคนิคการนำภาพมาแสดงใน Comment แบบ Dynamic

การนำภาพมาแสดงใน Comment เป็นวิธีที่ช่วยอธิบายค่าในเซลล์ได้ดีมากวิธีหนึ่งครับ เนื่องจาก Comment นั้นสามารถที่จะกำหนดให้ซ่อนเอาไว้ได้ เมื่อนำเมาส์มาชี้ในเซลล์จึงค่อยแสดง Comment ออกมา
สำหรับวิธีที่จะแนะนำต่อไปนี้นั้นใช้ VBA เข้ามาช่วยเพื่อแสดงรูปตามค่าในเซลล์ เมื่อเปลี่ยนค่าในเซลล์แล้ว ภาพใน Comment ก็จะเปลี่ยนตาม Surprised smile
ซึ่งมีวิธีการดังต่อไปนี้ครับ
  1. เก็บภาพไว้ใน Folder ที่กำหนด ตามตัวอย่างนี้เก็บไว้ที่ Folder D:
  2. นำรายชื่อภาพที่ต้องการแสดงมาไว้ในตาราง Excel ตามตัวอย่างจะเก็บไว้ที่ D2:D5
  3. สร้าง Validation ที่เซลล์ A1 โดยนำค่าตามข้อ 2. มาแสดงเพื่อให้มี Dropdown สำหรับเลือกค่าที่ต้องการได้
  4. เขียน VBA Code ตามด้านล่าง โดย
Smile วาง Code ด้านล่างไว้ที่ Sheet1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
ChangePicInComment
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.DisplayCommentIndicator = xlCommentAndIndicator
Else
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End If
End Sub

Winking smile และวาง Code ด้านล่างไว้ที่ Module ปกติ


Sub ChangePicInComment()
Dim PicName As String
On Error Resume Next
PicName = Range("A1")
Range("A1").Comment.Shape.Select
Selection.ShapeRange.Fill.UserPicture "D:\" & PicName & ".jpg"
Range("A1").Select
End Sub


ภาพการนำภาพมาแสดงใน Comment แบบ Dynamic

PicInCmt

0 ความคิดเห็น:

แสดงความคิดเห็น

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design Downloaded from Free Blogger Templates Download | free website templates downloads | Vector Graphics | Web Design Resources Download.