'续上页 '以下为模块中进行相关人机对话然后在当前光标处插入图片 Public SLT As Single, STP As Single, PH As Single, PW As Single, PicName As String Sub InsertPicture() Dim Mydialog As FileDialog, MyPicture As Shape, MyText As Shape Dim PL As Single, PT As Single, Pcount As Integer, strBmp As String On Error Resume Next Application.ScreenUpdating = False If SLT = -1 Or STP = -1 Or Selection.Type <> wdSelectionIP _ Then MsgBox "请将光标定位于页面中或者错误的光标选定项目", vbOKOnly + vbCritical, "Microsoft Word": Exit Sub ' MsgBox SLT & STP If PH * PW = 0 Then SetHW PicName = ActiveDocument.Variables("PicName").Value Set Mydialog = Application.FileDialog(msoFileDialogOpen) With Mydialog .Filters.Clear .Filters.Add "Images", "*.Bmp; *.Gif; *.Jpg; *.Jpeg", 1 .AllowMultiSelect = False If .Show = -1 Then strBmp = .SelectedItems(1) Else Exit Sub End If With ActiveDocument Pcount = .Variables("Pcount").Value Pcount = Pcount + 1 .Variables("Pcount").Value = Pcount Set MyPicture = .Shapes.AddPicture(FileName:=strBmp, _ Left:=SLT, Top:=STP, Width:=PW, Height:=PH) With MyPicture .Name = "Pone" & Pcount .LockAnchor = False .WrapFormat.Side = wdWrapBoth End With Set MyText = .Shapes.AddTextbox(msoTextOrientationHorizontal, SLT, STP + PH, PW, 25) With MyText .Name = "Ptwo" & Pcount .Line.Visible = msoFalse .TextFrame.TextRange.Text = PicName & Pcount .TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphCenter End With .Shapes.Range(Array("Pone" & Pcount, "Ptwo" & Pcount)).Group.Name = "Pthree" & Pcount .Shapes("Pthree" & Pcount).WrapFormat.AllowOverlap = False End With End With Application.ScreenUpdating = True End Sub '*********************************** '打开窗体 Sub SetHW() UserForm1.Show End Sub '*********************************** '重新定义编号等 Sub SetRestore() Dim Y As String Y = InputBox("请在此输入重新开始的编号值", "Microsoft Word 编号重置") If Y = "" Then ActiveDocument.Variables("Pcount").Value = 0 Else ActiveDocument.Variables("Pcount").Value = CInt(Y) - 1 End If End Sub '*********************************** '将初始值写入文档变量中,相当于初始化文档变量 Sub test() ActiveDocument.Variables.Add Name:="Pcount", Value:=0 ActiveDocument.Variables.Add Name:="PicName", Value:="照片" End Sub '*********************************** '观测文档变量值的变化 Sub GetTest() MsgBox ActiveDocument.Variables(1) MsgBox ActiveDocument.Variables(2) End Sub '*********************************** '当发生错误后类模块可能被终止,通过此代码重新触发类模块进程 Sub ErrReset() Register_Event_Handler End Sub '*********************************** |