我在excel中创建了一个宏,它使用excel报告将大量表复制并粘贴到power point presentation中。使用' Keep source formatting'粘贴表格。方法和粘贴宏后,如果字体较小,将字体大小更改为7,并将表放在幻灯片上的正确位置。问题是宏在两个应用程序之间跳过并且每次粘贴都很耗时,所以有时宏崩溃/冻结 - 例如当为同一报告运行宏时,我会收到不同的结果 - 有时会成功生成表示几分钟后,幻灯片在幻灯片15上崩溃,在另一次运行中,它在41号幻灯片上崩溃,完全相同的报告。有没有办法运行宏作为后台进程,以启用excel性能,没有错误或任何方式,以避免excel粉碎...我会感谢任何建议/建议!
以下是我用来粘贴表格并在复制所需表格范围时更改字体大小的支持宏代码:
Sub PastewithSourceFormatting_table(iSlide As Integer, table_name As Object)
Dim shapes_number As Integer
Dim shapes_number_new As Integer
Dim v_size As Byte
Dim row_num As Integer
Dim col_num As Integer
shapes_number_new = 0
shapes_number = 0
v_size = 0
row_num = 0
col_num = 0
Set PPSlide = PPPres.Slides(iSlide)
PPSlide.Select
shapes_number = PPSlide.Shapes.Count
Do Until shapes_number_new = shapes_number + 1
With PPSlide
PPApp.CommandBars.ExecuteMso ("PasteSourceFormatting")
Application.Wait (Now + TimeValue("0:00:01"))
PPApp.CommandBars.ReleaseFocus
shapes_number_new = .Shapes.Count
End With
Loop
Application.Wait (Now + TimeValue("0:00:01"))
Application.CutCopyMode = False
Set table_name = PPSlide.Shapes.Item(shapes_number_new)
'---------check font size
v_size = table_name.Table.Cell(1, 1).Shape.TextFrame.TextRange.Font.Size
row_num = table_name.Table.Rows.Count
col_num = table_name.Table.Columns.Count
If v_size < 7 Then
Dim i, j As Integer
For i = 1 To row_num
For j = 1 To col_num
If table_name.Table.Cell(i, j).Shape.TextFrame.HasText = msoTrue Then
table_name.Table.Cell(i, j).Shape.TextFrame.TextRange.Font.Size = 7
End If
Next j
Next i
Else
End If
Application.Wait (Now + TimeValue("0:00:01"))
End Sub