① 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