office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

Word VBA在文檔最後一頁右下角插入圖片(蓋章)

2019-11-08 17:22:00
tmtony8
原創
6845

在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


如圖,圖片成功插入到文檔的右下角

    分享