Trong file bạn hỏi rằng:Em có ghi nội dung vấn đề cụ thể trên file, đại khái là em muốn chèn thêm hình ảnh trên form, thay đổi theo giá trị của ComboBox.
Mong mọi người giúp đỡ, cám ơn.
Câu trả lời là đượcCó thể sử dụng hình trong Comment ô B6 được không ? Hay phải có cần file hình đi kèm ?
Private Sub ComboBox1_Change()
[COLOR=#0000cd] Dim rng As Range, Comm As Comment, shp As Shape, IPic As IPictureDisp
Dim i As Long
On Error Resume Next
Me.Image1.Picture = Nothing[/COLOR]
If Me.ComboBox1.Value = "" Then
For i = 1 To 3
Me.Controls("TextBox" & i).Value = ""
Next i
Else
Me.TextBox1.Value = ComboBox1.Column(1)
Me.TextBox2.Value = ComboBox1.Column(2)
Me.TextBox3.Value = ComboBox1.Column(3)
[COLOR=#0000cd]Set rng = Sheet5.Range("C:C").Find(Me.TextBox3.Text, , xlValues, xlPart)
If Not rng Is Nothing Then Set Comm = rng.Offset(, -1).Comment
If Not Comm Is Nothing Then
Comm.Visible = True
Set shp = Comm.Shape
shp.Shadow.Visible = msoFalse
shp.Line.Visible = msoFalse
shp.AutoShapeType = msoShapeRectangle
Set IPic = PictureFromObject(shp)
Comm.Visible = False
Me.Image1.Picture = IPic
End If[/COLOR]
End If
End Sub
[COLOR=#ff0000]Private Sub UserForm_Initialize()
Me.Image1.PictureSizeMode = fmPictureSizeModeStretch
End Sub[/COLOR]
[/B]Private Declare Function OleCreatePictureIndirect Lib "olepro32" (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long[B]
Xin hỏi: Bạn copy sang FILE KHÁC TRÊN CÙNG 1 MÁY TÍNH hay COPY SANG MÁY KHÁC?Anh ndu cho em hỏi, file đính kèm tải về test ok, em copy code module sang file khác ứng dụng thì bị báo lỗi Compile error user-defined type not defined
Cảm ơn anh, mong anh hướng dẫn lỗi này dùm.Mã:Private Declare Function OleCreatePictureIndirect Lib "olepro32" (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Em gửi file em đang thực hiện đây. Em chỉ làm trên 1 máy và sử dụng office 2003.
Tiện thể anh xem có thể rút gọn việc lấy giá trị cho textbox65 (nhóm cáp) mà không cần cột phụ (cột HE) không.
Cảm ơn anh.
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
dzạ, em copy lại đúng rồi. File test em up lên sửa lại chạy ok rồi.
Mà khi đưa vào file lớn hơn, lúc chạy đc lúc không đc. Em không hiểu vấn đề tại sao bị vậy nữa.
Lúc đầu mở form lên, hiện ảnh ok, nhưng khi kéo xuống dữ liệu xa hơn thì nó hiện toàn màu đen.
Tắt file mở lại, thì có khi giống như trên, có khi thì mấy hình đầu lúc nãy coi đc thì giờ cũng hiện toàn màu đen.
Chỉ bị file lớn, cấu trúc y hệt file test em đã gửi.
Em xem bik vấn đề ở đâu chỉ em sửa.
Cám ơn anh.
Tạm ổn rồi, cám ơn anh nhiều.
Anh cho em hỏi thêm là mình chèn hình vào comment rồi xuất ra image trên form, nên sử dụng hình như thế nào để chất lượng hình tốt nhất.
Hiện tại em sử dụng JPG, ảnh gốc chất lượng tốt, nhưng khi chuyển thành comment thì chất lượng giảm đáng kể, xuất lên form thì càng giảm hơn nữa.
Anh có kinh nghiệm gì chỉ giúp em.
Em xin gửi lên file sử dụng image bằng LoadPicture, file ảnh của em rất rõ, nhưng khi load lên bằng form ẽxcel chất lượng giảm đáng kể (tương đương khi dùng comment của anh ndu), có công cụ nào xuất được ảnh có độ phân giải tốt như ảnh gốc không ?
Em cám ơn.
em mới đem đi thử ở vài máy, máy nào cũng bị bể chữ trên hình, nhìn rất xấu.
Anh xem dùm hình trong file em gửi bài số #11 đó, chứ hình khung cảnh trong mấy file trc thì máy em nhìn cũng ok. Không hiểu sao mấy file hình có chữ thì nhìn hư hết.
Mấy file hình đó là em vẽ trên word, rồi print screen qua paint save lại.
Có phải do cách tạo hình của em ko đúng nên hình nó bị hư khi chèn lên form không.
Mong anh chỉ giúp. Cám ơn anh.
[COLOR=#333333]Try this,[/COLOR]
[COLOR=#333333]On worksheet, in design mode[/COLOR]
[COLOR=#333333]select Image control.[/COLOR]
[COLOR=#333333]Via properties window select Picture property[/COLOR]
[COLOR=#333333]Copy and paste on worksheet.[/COLOR]
[COLOR=#333333]Select newly created image[/COLOR]
[COLOR=#333333]Use Paste > As Picture > Copy Picture [/COLOR]
[COLOR=#333333]As shown on screen and Picture format.[/COLOR]
[COLOR=#333333]Now go to userform[/COLOR]
[COLOR=#333333]add image control[/COLOR]
[COLOR=#333333]select picture property and paste[/COLOR]
[COLOR=#333333]Sorry for not anwering before Andy but yesterday I had to leave...[/COLOR]
[COLOR=#333333]I was now trying your suggestion... and WOW!!! Indeed, it works if I reduce the size of the picture on the excel worksheet before I copy it to the image control in the userform...[/COLOR]
[COLOR=#333333]So I understood that I have to reduce the size of the picture if I want to display it on an image control in a userform. The PictureSizeModeZoom was distorting the image...[/COLOR]
[COLOR=#333333]Thank you a lot for your support Andy!! It helped a lot!!! =)[/COLOR]