代码之家  ›  专栏  ›  技术社区  ›  Arseny

如何在VBA中将图片(图形对象)复制到剪贴板?

  •  1
  • Arseny  · 技术社区  · 14 年前

    在Excel2003中,我需要复制一个图形对象( sheet.PageSetup.LeftFooterPicture

    我该怎么做?

    5 回复  |  直到 14 年前
        1
  •  2
  •   Community CDub    7 年前

    在2007年以前的Excel版本中,无法从页脚提取图形。您需要原始图像文件。

    this previous question

        2
  •  1
  •   marg    14 年前

    根据 MSDN Graphic Filename

    下面的代码可能会对您有所帮助。

    Sub yourMethod()
        copyGraphic Me.PageSetup.LeftFooterPicture
    End Sub
    
    Sub copyGraphic(srcGraphic As Graphic)
        Dim imagefolder As String
        Dim imageExtension As String
        Dim imagePath As String
    
        imagefolder = "D:\" '"
        imageExtension = ".gif"
    
        If InStr(1, srcGraphic.filename, ".") Then
            imagePath = srcGraphic.filename
        Else
            imagePath = imagefolder & srcGraphic.filename & imageExtension
        End If
    
        Me.Shapes.AddPicture imagePath, False, True, 10, 10, Round(srcGraphic.Width, 0), Round(srcGraphic.Height, 0)
    End Sub
    

    Me. 您的工作表和目标工作表的名称。

        3
  •  1
  •   Arseny    14 年前

    如前所述,问题是我无法从图形对象(LeftFooterPicture)中提取图片

    文件名应该包含文件的整个路径,如“C:\myimage.jpg”,但一旦保存工作表,它就会将文件名更改为“myiamge”,而不包含路径和扩展名。

    1. 在“Save”事件之前,我扫描所有的工作表并得到它们的图形,直到“Filename”有正确的内容(绝对路径,如C:\mypic.jpg)
    2. 我创建一个隐藏工作表并将所有图片添加为形状对象(Shapes.AddPicture with picture's path)

    3. 我将当前工作集名称和图片位置与形状名称绑定

        4
  •  0
  •   oopbase Jayachandran Murugesh    14 年前
    Private Sub Command1_Click()
    Clipboard.Clear
    Clipboard.SetData Picture1.Picture, vbCFBitmap
    Command1.Enabled = False
    End Sub
    

    这样你就可以把图片复制到剪贴板上。

        5
  •  0
  •   Debbie    14 年前

    希望有帮助。