我一直在编写的程序从工作簿中的各种来源读取信息,将信息重新排列到单独工作表上的几个紧凑表中,然后将这些表作为图像复制到单独的摘要表中。我把这个程序写成几个不同的子程序,由主程序调用。
当主程序运行时,它粘贴到摘要表中的图像具有正确的尺寸和位置,但它们是完全白色的。但是,当我运行负责复制这些图像的子例程时,它实际上成功地复制了正确的表。这是我用来复制和粘贴表格的代码,作为图像:
Sub ExtractToPresentation()
Call UnprotectAll
Application.DisplayAlerts = False
Application.CutCopyMode = False
startcell = Worksheets("Supplier Comparison").Cells(1, 1).Address
bottomcell = Worksheets("Supplier Comparison").Cells(21, 14).Address
Set copyrng = Worksheets("Supplier Comparison").Range(startcell, bottomcell) '.SpecialCells(xlCellTypeVisible)
copyrng.CopyPicture xlScreen, xlBitmap
With Worksheets("Presentation")
.Paste _
Destination:=.Range(SupSt)
End With
子例程继续,但其余的是每个附加表的上述代码的变体:
startcell = Worksheets("Rating Criteria").Cells(1, 1).Address
bottomcell = Worksheets("Rating Criteria").Cells(12, 7).Address
Set copyrng = Worksheets("Rating Criteria").Range(startcell, bottomcell)
copyrng.CopyPicture xlScreen, xlBitmap
With Worksheets("Presentation")
.Paste _
Destination:=.Range(CritSt)
End With
startcell = Worksheets("Comments").Cells(1, 1).Address
bottomcell = Worksheets("Comments").Cells(4, 14).Address
Set copyrng = Worksheets("Comments").Range(startcell, bottomcell)
copyrng.CopyPicture xlScreen, xlBitmap
With Worksheets("Presentation")
.Paste _
Destination:=.Range(CommSt)
End With
startcell = Worksheets("Component Table").Cells(1, 1).Address
bottomcell = Worksheets("Component Table").Cells(CompH, CompW).Address
Set copyrng = Worksheets("Component Table").Range(startcell, bottomcell)
copyrng.CopyPicture xlScreen, xlBitmap
With Worksheets("Presentation")
.Paste _
Destination:=.Range(CompSt)
End With
Application.DisplayAlerts = False
Call ProtectAll
End Sub
以 St、H 和 W 结尾的变量在前面的程序中定义,该程序确定每个表的大小。我不知道为什么这个程序可以完美地独立运行,但在其他程序之后运行时会返回空白图像。
如果有人想查看我的代码的其他部分,请告诉我。这个程序有大约 500 行,我不想一次全部转储。