作者:je荒也是种美 | 来源:互联网 | 2023-05-22 06:21
我正在编写一个循环文件夹的脚本,并根据某些条件创建图形,然后将这些图形导出到powerpoint.目前,创建130个图表需要290秒,其中286个由powerpoint使用.我怀疑这是一个主要原因是无法关闭powerpoint的screenupdd.我尝试使用http://skp.mvps.org/ppt00033.htm中的代码来解决这个问题.但是,我没有注意到任何影响.虽然我可以在后台使用alt-tab并保持powerpoint,但当切换到Powerpoint时,所有的更改都会显示出来,你基本上可以看到它如何减慢程序的速度.有谁知道我如何使用这段代码?它应该是一个类模块,我应该做什么或者我做错了什么?下面是我借用的代码片段以及我尝试调用它的示例:
Option Explicit
' UserDefined Error codes
Const ERR_NO_WINDOW_HANDLE As LOng= 1000
Const ERR_WINDOW_LOCK_FAIL As LOng= 1001
Const ERR_VERSION_NOT_SUPPORTED As LOng= 1002
' API declarations for FindWindow() & LockWindowUpdate()
' Use FindWindow API to locate the PowerPoint handle.
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
' Use LockWindowUpdate to prevent/enable window refresh
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
' Use UpdateWindow to force a refresh of the PowerPoint window
Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Property Let ScreenUpdating(State As Boolean)
Static hwnd As Long
Dim VersionNo As String
' Get Version Number
If State = False Then
VersiOnNo= Left(Application.Version, InStr(1, Application.Version, ".") - 1)
'Get handle to the main application window using ClassName
Select Case VersionNo
Case "8"
' For PPT97:
hwnd = FindWindow("PP97FrameClass", 0&)
Case "9"
' For PPT2K:
hwnd = FindWindow("PP9FrameClass", 0&)
Case "10"
' For XP:
hwnd = FindWindow("PP10FrameClass", 0&)
Case "11"
' For 2003:
hwnd = FindWindow("PP11FrameClass", 0&)
Case "12"
' For 2007:
hwnd = FindWindow("PP12FrameClass", 0&)
Case "14"
' For 2010:
hwnd = FindWindow("PPTFrameClass", 0&)
Case Else
Err.Raise Number:=vbObjectError + ERR_VERSION_NOT_SUPPORTED, _
Description:="Newer version."
Exit Property
End Select
If hwnd = 0 Then
Err.Raise Number:=vbObjectError + ERR_NO_WINDOW_HANDLE, _
Description:="Unable to get the PowerPoint Window handle"
Exit Property
End If
If LockWindowUpdate(hwnd) = 0 Then
Err.Raise Number:=vbObjectError + ERR_WINDOW_LOCK_FAIL, _
Description:="Unable to set a PowerPoint window lock"
Exit Property
Else
LockWindowUpdate (hwnd)
End If
Else
'Unlock the Window to refresh
LockWindowUpdate (0&)
UpdateWindow (hwnd)
hwnd = 0
End If
End Property
Sub TestSub()
' Lock screen redraw
If ScreenUpdatingOff = True Then ScreenUpdating = False
' --- Loop through charts in Excel and export them to Powerpoint
' Redraw screen again
ScreenUpdating = True
End Sub
提前谢谢了.很奇怪,这个功能并不容易获得,现在我需要你的帮助!