开发者

Export from Excel to Word with Header Image Issue

I'm attempting to create a VBA code in Excel that will export from Excel into Word, with header text and a header image. The header image should go on the right side of the Word header, with other header text on the left side of the Word header.

I can get the code to create a Word document and to create the header table. The problem is, the image is always pasted into the Word header in column 1, I need that header image in column 2. You can开发者_如何学Python see in the code I'm telling it to paste the image in column 2 however it always pastes in column 1. Any help would be greatly appreciated! Thank you!

    Sub Export()

    Dim obj As Object
    Dim newobj As Object

    Set obj = CreateObject("Word.Application")
    obj.Visible = True
    Set newobj = obj.Documents.Add

    Sheets("Sheet1").Cells.Copy
    newobj.Range.Paste

    Application.CutCopyMode = False
    obj.Activate

    With obj
        .Visible = True
        With newobj
            Set wdRng = .Sections(1).Headers(1).Range
            Set wdTbl = .Tables.Add(Range:=wdRng, NumRows:=4, NumColumns:=2)
            With wdTbl
            ThisWorkbook.Sheets("Header_Image").Shapes(1).CopyPicture xlScreen, xlBitmap
            .cell(1, 2).Range.PasteSpecial
            End With
        End With
    End With

    End Sub

I've tried many code variations, modifying the image formats, searching the web, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜