vba 如何在powerpoint vba中制作进度条?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2284530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a progress bar in powerpoint vba?
提问by aF.
How can I make a progress bar with PowerPoint VBA? It should be done as an animation on a slide.
如何使用 PowerPoint VBA 制作进度条?它应该作为幻灯片上的动画来完成。
回答by Todd Main
回答by Ben
This one will put the bar at the top and prevent it from appearing on the first slide (unlike the pptfaq script):
这将把栏放在顶部并防止它出现在第一张幻灯片上(与 pptfaq 脚本不同):
http://www.faronics.com/news/blog/how-to-add-a-progress-bar-to-powerpoint/
http://www.faronics.com/news/blog/how-to-add-a-progress-bar-to-powerpoint/
In Power Point, go to Tools > Macro > Visual Basic Editor.
In Office 2010 you might need to activate the Developer tab in order to get to the editor. The Mac version will take you there through Developer tab > Editor.
Once you are in the editor, go Insert > Module.
在 Power Point 中,转到“工具”>“宏”>“Visual Basic 编辑器”。
在 Office 2010 中,您可能需要激活“开发人员”选项卡才能访问编辑器。Mac 版本将带您进入开发人员选项卡 > 编辑器。
进入编辑器后,转到“插入”>“模块”。
Four. Paste the following code in this newly created module:
四。将以下代码粘贴到这个新创建的模块中:
Sub Presentation_Progress_Marker()
On Error Resume Next
With ActivePresentation
For N = 2 To .Slides.Count
.Slides(N).Shapes(“Progress_Marker”).Delete
Set s = .Slides(N).Shapes.AddShape(msoShapeRectangle, 0, 0, N * .PageSetup.SlideWidth /.Slides.Count, 10)
Call s.Fill.Solid
s.Fill.ForeColor.RGB = RGB(23, 55, 94)
s.Line.Visible = False
s.Name = “Progress_Marker” Next N: End With End Sub
Five. Close the editor. Finally, run the macro: Tools>Macro>Macros and select—Presentation_Progress_Marker.
五。关闭编辑器。最后,运行宏:Tools>Macro>Macros 并选择—Presentation_Progress_Marker。
回答by konahn
How about adding a progress bar control by Microsoft ?
微软添加一个进度条控件怎么样?
Since PowerPoint is not a real-time application, you might not be able to see the progress bar moving if you make it with some shapes. Sometimes you might end up seeing the final result only - only full bar or even nothing at all). On the contrary, the progress bar control is more 'real-time' or more up-to-time.(I admit that it's a little classic design.)
由于 PowerPoint 不是实时应用程序,因此如果使用某些形状制作它,您可能无法看到进度条在移动。有时您可能最终只能看到最终结果 - 只有完整的条形图或什至什么都没有)。相反,进度条控件更“实时”或更及时。(我承认这是一个有点经典的设计。)
Here's some steps for somebody:
这是某人的一些步骤:
To add a progress bar control, first you need to add a UserForm in VBE(Alt-F11) Window. (Menu: Insert - UserForm)
Right-click on the toolbox window that appears and choose additional control. Scroll down and check 'Microsoft Progress Bar Control, version x.0' (This control is provided by MSCOMCTL.OCX)
要添加进度条控件,首先需要在 VBE(Alt-F11) 窗口中添加一个 UserForm。(菜单:插入 - 用户表单)
右键单击出现的工具箱窗口并选择其他控件。向下滚动并选中“Microsoft Progress Bar Control, version x.0”(此控件由 MSCOMCTL.OCX 提供)
Click OK. Now you see the progress bar icon at the end of the tool list. Click it and draw a progress bar on UserForm1. Resize the UserForm1 window. The smaller, the better. You can change the title of the window from 'UserForm1' to 'Progressing...' or any message you like by changing the Caption value in the Property window.
单击确定。现在您会在工具列表的末尾看到进度条图标。单击它并在 UserForm1 上绘制一个进度条。调整 UserForm1 窗口的大小。越小越好。您可以通过更改“属性”窗口中的“标题”值,将窗口标题从“UserForm1”更改为“Progressing...”或任何您喜欢的消息。
- Add a Module and put some code like below.
- 添加一个模块并放置一些如下所示的代码。
Option Explicit
Sub MyJob()
'Show the Progress Bar window
UserForm1.Show vbModeless 'vbModeless option should be added
Dim i As Long, Total As Long
Total = 200
Randomize
For i = 1 To Total
'put some code here. Especially, some jobs that take some time.
'for example, add a rounded box with random color on slide #1
With ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRoundedRectangle, i, i, 500, 200)
.Name = "Shape_" & i
.Fill.ForeColor.RGB = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)
.Adjustments(1) = 0.5
.Line.Visible = msoFalse
.TextFrame.TextRange = i
End With
'Update the Progress bar
UserForm1.ProgressBar1.Value = Int(i * 100 / Total)
'integer between 0 and 100. Otherwise, pops up an error
UserForm1.Repaint 'refresh the Userform
Next i
'close ProgressBar UserForm
Unload UserForm1
End Sub
By default, the value of the progress bar should be an integer between 0 and 100. If it's '101', you get an error. So be careful.
默认情况下,进度条的值应该是 0 到 100 之间的整数。如果是“101”,则会出现错误。所以要小心。
- Also, you can change the shape of the progress bar by changing the property values. For example, the bar size, the location(Top, Left), the minimum value(0) or the maximum value(by default, it's 100. But you can change it to 50 or any value.).You can also change them programmatically.
- 此外,您可以通过更改属性值来更改进度条的形状。例如,条形大小、位置(顶部、左侧)、最小值(0)或最大值(默认为 100。但您可以将其更改为 50 或任何值。)您也可以更改它们以编程方式。
The progress bar is somewhat old-fashioned, but useful for its faster(?) reaction than the user-created shape-type progress bar.
进度条有点老式,但比用户创建的形状类型的进度条反应更快(?)很有用。