snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub InsPic2()
Const strPath As String = "C:\"
Dim Imge, logopic As Object
Dim ImgFileFormat As String
Dim i As Integer
Dim obj As Object
For Each obj In ActiveSheet.Shapes
If obj.Name = "picture 46" Then
i = 1
End If
Next obj
If i = 1 Then
ActiveSheet.Unprotect Password:="1"
Range("B1").Select
ActiveSheet.Shapes("picture 46").Delete
Range("B1").Select
End If
Call locksheet2
Sheets("Logo2").Select
ChDrive strPath
ImgFileFormat = "Image Files (*.jpg*),*.jpg*"
ImgFileFormat = ImgFileFormat & ",PNG Files (*.png*),*.png*"
ImgFileFormat = ImgFileFormat & ",BMP Files (*.bmp*),*.bmp*"
Imge = Application.GetOpenFilename(ImgFileFormat)
If Imge <> "False" Then
ActiveSheet.Unprotect Password:="1"
Set logopic = ActiveSheet.Shapes.AddPicture(Filename:=Imge, linktofile:=msoFalse, savewithdocument:=msoCTrue, _
Left:=Range("b1").Left, Top:=Range("b1").Top, Width:=-1, Height:=-1)
With logopic
.Name = "picture 46"
.LockAspectRatio = msoTrue
.Height = 117.75
.Width = 66#
.Rotation = 0#
.IncrementLeft 3.75
.IncrementTop 1.25
End With
Call locksheet2
End If
End Sub