作品及代码如下:
fqoKZHl8.rar
(66.99 KB, 下载次数: 23)
Dim Ph As Single, Pw As Single
Sub InsertPicture()
Dim MyDialog As Dialog, MyPicture As Shape, MyText As Shape, n As Integer
Dim Pl As Single, Pt As Single, Dt As Single, Dl As Single, Pcount As Integer
On Error Resume Next
Application.ScreenUpdating = False
If Ph * Pw = 0 Then Call SetHW
Set MyDialog = Application.Dialogs(wdDialogInsertPicture)
With MyDialog
If .Show = -1 Then
With Me
Pcount = .Variables("Pcount").Value
Dt = .PageSetup.TopMargin
Dl = .PageSetup.LeftMargin
n = .Shapes.Count
Set MyPicture = .Shapes(n)
With MyPicture
.Name = "Pone"
.LockAspectRatio = msoFalse
.LockAnchor = False
.WrapFormat.Side = wdWrapBoth
.Height = Ph
.Width = Pw
Pt = .Top + Dt
Pl = .Left + Dl
End With
Set MyText = .Shapes.AddTextbox(msoTextOrientationHorizontal, Pl, Pt + MyPicture.Height, MyPicture.Width, 25)
With MyText
.Name = "Ptwo"
.Line.Visible = msoFalse
.TextFrame.TextRange.Text = "照片" & Pcount + 1
Me.Variables("Pcount").Value = Pcount + 1
.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
.Shapes.Range(Array("Pone", "Ptwo")).Group.Name = "Pthree" & Pcount
.Shapes("Pthree" & Pcount).WrapFormat.AllowOverlap = False
End With
End If
End With
Application.ScreenUpdating = True
End Sub
Sub SetHW()
Dim MyValue As String, L As Byte
On Error GoTo Errhandle
ST: MyValue = InputBox("请在此输入照片的高度(厘米)和宽度(厘米),以*号分隔", "Microsoft Word")
If MyValue = "" Then Exit Sub
L = InStr(MyValue, "*")
If L = 0 Then
GoTo Errhandle
Else
Ph = CentimetersToPoints(CSng(Mid(MyValue, 1, L - 1)))
Pw = CentimetersToPoints(CSng(Mid(MyValue, L + 1, Len(MyValue) - L)))
End If
Exit Sub
Errhandle:
MsgBox "无效数据,请重新正确输入!", vbOKOnly + vbInformation
GoTo ST
End Sub
Sub SetZero()
Me.Variables("Pcount").Value = 0
End Sub |