Re: รบกวนอาจารย์ ช่วยเรื่อง Code VB ตรวจสอบการลบและแทรกรูปภาพด้ว
Posted: Fri Oct 06, 2017 9:22 pm
คลังคำตอบแห่งความรู้จากคนไทย เพื่อโลกที่ต้องการเข้าใจในสิ่งเล็ก ๆ อย่างลึกซึ้ง
http://www.snasui.com/
Code: Select all
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