如何将图像从 Excel 中的单元格传输到 Word header(左)VBA
How can I transfer an image from a cell in Excel to the Word header (left) VBA
如何在 header 新建的 Word 文档中插入 Excel Celle (C1) by VBA 的图片而不带格式(无单元格颜色)?
logo.copy
Set objHeader = myDoc.Sections(1).Headers(1).Range
objHeader.Paste
谢谢!
请尝试下一种方式:
Sub InsertHeaderPict()
'copy picture from Excel (open session, active sheet):
Dim appExcel As Excel.Application, ws As Excel.Worksheet
Set appExcel = GetObject(, "Excel.Application")
Set ws = appExcel.ActiveWorkbook.ActiveSheet
ws.Shapes("Picture 1").CopyPicture xlScreen, xlBitmap 'use here your real picture name
'create a table of a row, 3 columns and paste the copied picture in its first cell:
Dim oSec As Word.Section, rng As Range
Set oSec = ActiveDocument.Sections(1)
Set rng = oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
With rng
.Tables.Add Range:=rng, NumRows:=1, NumColumns:=3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitWindow
With .Tables(1)
.Borders.InsideLineStyle = wdLineStyleNone
.Borders.OutsideLineStyle = wdLineStyleNone
.Rows.SetLeftIndent LeftIndent:=-37, RulerStyle:=wdAdjustNone
.Cell(1, 1).Range.PasteSpecial
End With
End With
End Sub
Excel 打开会话的活动 sheet 中必须有图片。使用这个真实的图片名称而不是“图片 1”和 运行 代码。
我相信你的想法是正确的,只需要使用copypicture
和pastespecial
这是我的代码片段,基本上与我只是使用形状对象而不是范围做同样的事情。
Set reportHeader = masterReport.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
masterWorkbook.Worksheets("Template").Shapes("LogoSmall").CopyPicture
reportHeader.PasteSpecial
再次感谢 this post 我最初找到这个答案的地方。
如何在 header 新建的 Word 文档中插入 Excel Celle (C1) by VBA 的图片而不带格式(无单元格颜色)?
logo.copy
Set objHeader = myDoc.Sections(1).Headers(1).Range
objHeader.Paste
谢谢!
请尝试下一种方式:
Sub InsertHeaderPict()
'copy picture from Excel (open session, active sheet):
Dim appExcel As Excel.Application, ws As Excel.Worksheet
Set appExcel = GetObject(, "Excel.Application")
Set ws = appExcel.ActiveWorkbook.ActiveSheet
ws.Shapes("Picture 1").CopyPicture xlScreen, xlBitmap 'use here your real picture name
'create a table of a row, 3 columns and paste the copied picture in its first cell:
Dim oSec As Word.Section, rng As Range
Set oSec = ActiveDocument.Sections(1)
Set rng = oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
With rng
.Tables.Add Range:=rng, NumRows:=1, NumColumns:=3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitWindow
With .Tables(1)
.Borders.InsideLineStyle = wdLineStyleNone
.Borders.OutsideLineStyle = wdLineStyleNone
.Rows.SetLeftIndent LeftIndent:=-37, RulerStyle:=wdAdjustNone
.Cell(1, 1).Range.PasteSpecial
End With
End With
End Sub
Excel 打开会话的活动 sheet 中必须有图片。使用这个真实的图片名称而不是“图片 1”和 运行 代码。
我相信你的想法是正确的,只需要使用copypicture
和pastespecial
这是我的代码片段,基本上与我只是使用形状对象而不是范围做同样的事情。
Set reportHeader = masterReport.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
masterWorkbook.Worksheets("Template").Shapes("LogoSmall").CopyPicture
reportHeader.PasteSpecial
再次感谢 this post 我最初找到这个答案的地方。