office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Word VBA在文档最后一页右下角插入图片(盖章)

2019-11-08 17:22:00
tmtony8
原创
6896

在Word文档中,我们会录入指定的图片。

如何在Word中的指定的位置插入添加图片呢?如把E:\logo.png添加到文档的最后一页



通过下面的代码,把图片插入到Word文档的最后一页的右下角


Sub AddPic()
    
    Dim p As Page
    Dim pos As Long
    Dim rng As Range
    Dim shp As Shape
    Dim shpDate As Shape
    Dim WdInlineSign As InlineShape
    Dim xOffer As Long
    Dim yOffer As Long
    Set p = ActiveWindow.Panes(1).Pages(Selection.Information(wdActiveEndPageNumber))
    pos = p.Rectangles(1).Range.End - 1
    Set rng = ActiveDocument.Range(pos, pos)
    ActiveDocument.Paragraphs.Last.Range.Select
    Set WdInlineSign = Selection.InlineShapes.AddPicture(FileName:="E:\logo.png", LinkToFile:=False, SaveWithDocument:=True, Range:=rng)
'    WdInlineSign.Select
'    Selection.ShapeRange.WrapFormat.Type = wdWrapFront
    Set shp = WdInlineSign.ConvertToShape
    
    
    
    
    
    xOffer = ActiveDocument.PageSetup.RightMargin
    yOffer = ActiveDocument.PageSetup.BottomMargin
'    595 277  90
    shp.Left = p.Width - shp.Width - xOffer
    shp.Top = p.Height - shp.Height - yOffer
    
    shp.ZOrder msoBringInFrontOfText
    
    
'    WdInlineSign.Select
'    Selection.ShapeRange.WrapFormat.Type = wdWrapFront
    
    dblLeft = shp.Left
    dblTop = shp.Top + shp.Height
    dboWidth = shp.Width
End Sub


如图,图片成功插入到文档的右下角

    分享