word批量插入图片及其文件名进行打印

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

word宏批量插入图片及其文件名
方法:word2003>工具>宏>▲宏>
输入宏名:InsertPics
创建>将以下代码粘贴到文本框,然后关闭
工具>宏>InsertPics>运行>到文件夹选择图片即可
Function Basename(FullPath) '取得文件名
Dim x, y
Dim tmpstring
tmpstring = FullPath
x = Len(FullPath)
For y = x To 1 Step -1
If Mid(FullPath, y, 1) = "\" Or _
Mid(FullPath, y, 1) = ":" Or _
Mid(FullPath, y, 1) = "/" Then
tmpstring = Mid(FullPath, y + 1)
Exit For
End If
Next
Basename = Left(tmpstring, Len(tmpstring) - 4)
End Function
Sub InsertPics()
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(1.54) '上页边距
.BottomMargin = CentimetersToPoints(1.54) '下页边距
.LeftMargin = CentimetersToPoints(1) '左页边距
.RightMargin = CentimetersToPoints(1) '右页边距
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5) '页眉
.FooterDistance = CentimetersToPoints(1.75) '页脚
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7) '纸张大小
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeLineGrid
End With
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type <> wdPrintView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
With ActiveDocument.PageSetup.TextColumns
.SetCount NumColumns:=1 '分为1栏
.EvenlySpaced = True
.LineBetween = False
'.Width = CentimetersToPoints(9.12) '根据需要设置栏宽及栏间距
'.Spacing = CentimetersToPoints(0.75)
End With
Dim myfile As FileDialog
Dim n
Set myfile = Application.FileDialog(msoFileDialogFilePicker)
With myfile
.InitialFileName = "C:\"
If .Show = -1 Then
For Each fn In .SelectedItems
Set mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True)
'mypic.Width = 400 '根据需要设置
' mypic.Height = 300
If Selection.Start = ActiveDocument.Content.End - 1 Then '如光标在文末
Selection.TypeParagraph '在文末添加一空段
Else
Selection.MoveDown
End If
Selection.Text = "Plot" + Trim(Str(n)) + " " + Basename(fn) '函数取得文件名
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.EndKey
If Selection.Start = ActiveDocument.Content.End - 1 Then '如光标在文末
Selection.TypeParagraph '在文末添加一空段
Else
Selection.MoveDown
End If
n = n + 1
Next fn
Else
End If
End With
Set myfile = Nothing
End Sub。

相关文档
最新文档