2012-01-05 48 views
0

我正在尝试这几个小时,但我无法弄清楚如何在Excel 2010中在我的背景中获得图像作为信纸。在所有方面,似乎我只是无法获得它从左上角传播到右下角。插入和打印文具

我可以用宏来实现吗?还是有其他方法可以做到这一点?

+0

抱歉,但我不确定我是否了解您的问题。你的意思是你想要在滚动工作表时保持静止的图像?或者当你打印时你想要有背景图片吗? – JMax 2012-01-05 10:22:39

+0

请参阅我对chris neilsen的回答的评论。 – jroeleveld 2012-01-05 13:44:15

回答

0

参见microsoft link

引述
“在Excel中,可以使用图像作为片材背景仅用于显示目的。一种片材背景不打印,并且不保留在个体工作表或作为网页保存的项目仅在将整个工作簿作为网页发布时才会保留
重要由于不打印工作表背景,因此无法将其用作水印。通过在页眉或页脚中插入图形来实现水印。“

+0

我不必打印它。我有一个宏将其保存为PDF。图像必须覆盖完整的A4尺寸(当选择A4格式时),只需要在一张(A4)页面和一张纸上。 – jroeleveld 2012-01-05 13:43:30

0

这段代码会让你选择一个图片(你已经可以有一个适应这样的代码),它会调整图片以适应了printArea并调整它了printArea的左上角:

Option Explicit 

Private Sub Test() 
    Dim PicLocation As String 
    Dim MyRange As Range, TargetCell As Range 

    Set MyRange = Range(ActiveSheet.PageSetup.PrintArea) 
    Set TargetCell = MyRange.Cells(1, 1) 

    PicLocation = Application.GetSaveAsFilename("C:\", "Image Files (*.jpg),*.jpg", , "Specify Image Location") 

    If PicLocation <> "False" Then 
     ActiveSheet.Pictures.Insert(PicLocation).Select 
    Else 
     Exit Sub 
    End If 

    With Selection.ShapeRange 
     .LockAspectRatio = msoTrue 
     If .Width > .Height Then 
      .Width = MyRange.Width 
      If .Height > MyRange.Height Then .Height = MyRange.Height + ActiveSheet.PageSetup.HeaderMargin + ActiveSheet.PageSetup.BottomMargin 
     Else 
      .Height = MyRange.Height 
      If .Width > MyRange.Width Then .Width = MyRange.Width + ActiveSheet.PageSetup.LeftMargin + ActiveSheet.PageSetup.RightMargin 
     End If 
     .Left = TargetCell.Left - ActiveSheet.PageSetup.LeftMargin 
     .Top = TargetCell.Top - ActiveSheet.PageSetup.HeaderMargin 
    End With 

    With Selection 
     .Placement = xlMoveAndSize 
     .PrintObject = True 
    End With 
End Sub 
+0

谢谢。它看起来很有前途,而且很有效。但是,并不像我希望的那样。我的目标是覆盖整个工作表。我认为'Range(ActiveSheet.PageSetup.PrintArea)'不能在单元格之外获得图像(在空白边缘) – jroeleveld 2012-01-05 14:49:55

+0

实际上,您可以调整图片的大小,使其大于范围区域(更改宽度和高度在代码中)。你也可以改变移位('.Left'和'.Top') – JMax 2012-01-05 19:55:49

+0

你可以给语法吗?我不知道如何完成它。我的VBA知识不是很准确。 – jroeleveld 2012-01-06 08:44:19