① Excel VBA錛孷BA紼嬪簭浠g爜鏀瑰彉鍥劇墖鍐呭
1.ALT+F11鎵撳紑VBE緙栬緫鍣錛屾柊寤轟竴涓妯″潡1錛岃緭鍏ュ備笅浠g爜錛
Sub picxz() '浠ユ彃鍏ュ浘鐗囨枃浠跺師鍚嶇О浣滀負鍥懼艦鍚嶇О錛屽崟鍏冩牸澶у皬涓哄熀鍑嗭紝渚濇″厛琛屾柟鍚戝啀鍒楁柟鍚戞彃鍏ワ紝鍗沖厛A1,A2....鍐岯1,B2....渚濇$被鎺
Dim picname As Variant, p As Shape, pname As String, stly, p1 As Shape, pnamewr As String, x As Byte, x1 As Byte, itop, ileft, iheight, iwidth, l As Long, h As Long
Const hs As Long = 65536 '姣忓垪鎵鑳芥彃鍏ュ浘鐗囩殑鏈澶т釜鏁
stly = vbQuestion & vbYesNo
l = -Int(-Sheets("鍥懼簱").Shapes.Count / hs) '鍒楀彿
h = Sheets("鍥懼簱").Shapes.Count - (l - 1) * hs '琛屽彿
picname = Application.GetOpenFilename(FileFilter:="鍥劇墖鏂囦歡 (*.jpg; *.gif;*.bmp),*.jpg; *.gif;*.bmp,鎵鏈夋枃浠(*.*),*.*", _
Title:="鍥劇墖閫夋嫨", MultiSelect:=False)
If picname <> False Then
pname = Split(Dir(picname), ".", 2)(0) '鍙栧浘鐗囨枃浠跺師鍚嶇О
pnamewr = pname
itop = Sheets("鍥懼簱").Cells(h, l).Top '紜瀹氬潗鏍
ileft = Sheets("鍥懼簱").Cells(h, l).Left
iheight = Sheets("鍥懼簱").Cells(h, l).Height '紜瀹氬ぇ灝
iwidth = Sheets("鍥懼簱").Cells(h, l).Width
For Each p In Sheets("鍥懼簱").Shapes
If p.Name = pname Then
x = MsgBox("鍙戠幇浣犵殑鍥懼簱涓宸茬粡瀛樺湪鍚屽悕鍥劇墖錛岃風『瀹氭槸鍚︿負鏂板浘鐗囷紵", stly, "鍥劇墖閲嶅悕錛岃﹀憡錛")
If x = 7 Then
Exit Sub
Else
x1 = MsgBox("鎮ㄧ『瀹氶渶瑕佹浛鎹㈠悕涓猴細銆" & pname & "銆嬬殑鍥劇墖鍚楋紵", stly, "鍥劇墖鏇挎崲,璀﹀憡錛")
If x1 = 6 Then
itop = Sheets("鍥懼簱").Shapes(pname).Top
ileft = Sheets("鍥懼簱").Shapes(pname).Left
iheight = Sheets("鍥懼簱").Shapes(pname).Height
iwidth = Sheets("鍥懼簱").Shapes(pname).Width
Sheets("鍥懼簱").Shapes(pname).Delete
Else
chongshu:
If pnamewr = "" Then
pnamewr = InputBox("鎮ㄥ皻鏈瀵瑰浘鐗囧懡鍚嶏紝闇瑕佹g『鍛藉悕錛屾柟鑳芥彃鍏ユゅ浘鐗囷紒", "鍥劇墖鍛藉悕")
Else
pnamewr = InputBox("鎮ㄧ殑鍥懼簱宸茬粡瀛樺湪浠ャ" & pnamewr & "銆嬩負鍚嶇О鐨勫浘鐗囷紝闇瑕侀噸鏂板懡鍚嶏紝鏂硅兘鎻掑叆姝ゅ浘鐗囷紒", "鍥劇墖鍛藉悕")
End If
If pnamewr = "" Or pnamewr = pname Then
jinggao:
MsgBox "璀﹀憡錛佽緭鍏ヤ負絀烘垨涓哄悓鍚嶏紒璇風戶緇杈撳叆", vbExclamation, "鍥劇墖鍛藉悕璀﹀憡錛"
GoTo chongshu
End If
For Each p1 In Sheets("鍥懼簱").Shapes
If p1.Name = pnamewr Then GoTo jinggao
Next
End If
End If
End If
Next
ActiveSheet.Pictures.Insert(picname).Select
With Selection.ShapeRange
.Name = pnamewr
.LockAspectRatio = msoFalse
.Top = itop
.Left = ileft
.Height = iheight
.Width = iwidth
.Rotation = 0#
End With
End If
End Sub