کد:
Sub InsertCommentImage()
Dim commentBox As Comment
' Clear any comments before attempting to add them.
ActiveCell.ClearComments
' Define the comment as a local variable and assign the file name from the
' cellAddress input parameter to the comment of a cell.
[COLOR=#ff0000]url_path = Range("A1").Valueبا سلام خدمت دوستان عزیز
در این آموزش قصد دارم نحوه قرار دادن یک عکس در اکسل رو از طریق آدرس عکس (لینک عکس) به شما توضیح بدم.
چند روش برای این منظور وجود داره. ساده ترین روش اینه که خود عکس رو دقیقا وارد اکسل کنیم (شبیه حالتی که عکس در سیستم هست و ما از طریق insert picture عکس رو وارد شیت میکنیم. (روش 1)
در حالت بعدی ما میتونیم عکس رو بعنوان یک کامنت به سلول اضافه کنیم. در این روش هر سلولی که انتخاب شده باشه یک کامنت بهش اضافه میشه و داخل کامنت عکس مورد نظر لود میشه (روش 2)
در روش بعدی ما میتونیم عکس رو داخل یک shape اضافه کنیم. اشکالی که قابلیت fill دارند مثل مستطیل یا بیضی یا ... میتونیم عکس رو داخل اون اشیاء اضافه کنیم (روش 3)
حالت های دیگه هم شبیه همین سه روش هست که دیگه از توضیح اونها صرف نظر میکنم
حالا بریم سراغ کدهایی که باید نوشته بشه
روش اول:
کد:
Sub InsertPicture()
v = Range("A1").Value
ActiveSheet.Pictures.Insert (v)
End Sub
روش دوم:
Set commentBox = Application.ActiveCell.AddComment
With commentBox
.Text Text:=""
With .Shape
.Fill.UserPicture (url_path)
.ScaleHeight 3, msoFalse, msoScaleFromTopLeft
.ScaleWidth 2.4, msoFalse, msoScaleFromTopLeft
End With
' Set the visible to True when you always want the image displayed, and
' to False when you want it displayed only when you click on the cell.
.Visible = False
End With
End Sub
آدرس عکس در سلول A1 نوشته شده
[/COLOR]
کد:
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub InsertInFrame()
Dim url_path As String
Dim file_path As String
[COLOR=#ff0000]url_path = Range("A1").Value
روش سوم:
file_path = ThisWorkbook.Path & "\" & "Image.png"
' Download picture
DownloadfromWeb = URLDownloadToFile(0, url_path, file_path, 0, 0)
' Load picture
With [COLOR=#008000]ActiveSheet.Shapes("Rectangle 1").Fill[/COLOR]
.Visible = msoTrue
.UserPicture file_path
.TextureTile = msoFalse
End With
' Delete Saved file
Kill file_path
End Sub
آدرس عکس در سلول A1 نوشته شده
در این قسمت نام شیء که اضافه کردین رو مینویسید
[/COLOR]
کامنت