snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub InsImge()
Const strPath As String = "C:\"
Dim Imge
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
ActiveSheet.Protect Password:="1", DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Logo").Select
ChDrive strPath
ImgFileFormat = "Image Files (*.jpg;*.png),*.jpg;*.png"
Imge = Application.GetOpenFilename(ImgFileFormat)
If Imge <> "False" Then
ActiveSheet.Unprotect Password:="1"
Range("B1").Select
ActiveSheet.Pictures.Insert(Imge).Name = "picture 46"
Range("A1").Select
Selection.Offset(0, 1).Select
ActiveSheet.Shapes("picture 46").Select
With Selection
.Height = ActiveCell.Height - 2
.ShapeRange.IncrementTop 1
.ShapeRange.IncrementLeft (ActiveCell.Width - Selection.Width) / 2
End With
Range("D2").Select
ActiveSheet.Protect Password:="1", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End Sub
Sub InsImge()
Const strPath As String = "C:\"
Dim Imge
Dim ImgFileFormat As String
Dim i As Integer
Dim obj As Object
ActiveSheet.Unprotect Password:="1"
With ActiveSheet
For Each obj In .Shapes
If obj.Name = "picture 46" Then
' i = 1
obj.Delete
Exit For
End If
Next obj
End With
' If i = 1 Then
' ActiveSheet.Unprotect Password:="1"
' Range("B1").Select
' ActiveSheet.Shapes("picture 46").Delete
' Range("B1").Select
' End If
' ActiveSheet.Protect Password:="1", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Sheets("Logo").Select
ChDrive strPath
ImgFileFormat = "Image Files (*.jpg;*.png),*.jpg;*.png"
Imge = Application.GetOpenFilename(ImgFileFormat)
If Imge <> "False" Then
' ActiveSheet.Unprotect Password:="1"
Range("B1").Select
' ActiveSheet.Pictures.Insert(Imge).Name = "picture 46"
' Range("A1").Select
' Selection.Offset(0, 1).Select
' ActiveSheet.Shapes("picture 46").Select
With Selection
Set Imge = ActiveSheet.Shapes.AddPicture( _
Filename:=Imge, _
LinkToFile:=False, saveWithDocument:=True, _
Left:=Selection.Left, Top:=Selection.Top, _
Width:=Selection.Width, Height:=Selection.Height)
Imge.Name = "picture 46"
' .Height = ActiveCell.Height - 2
' .ShapeRange.IncrementTop 1
' .ShapeRange.IncrementLeft (ActiveCell.Width - Selection.Width) / 2
End With
Range("D2").Select
ActiveSheet.Protect Password:="1", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End If
End Sub