VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Office应用程序与VBA应用开发大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
'向下滚动,可用的引用列表直到你遇到需要对象库。注意在这个对话框,我已经检查了参词和幻灯片。版本号8指的是97处应用;9通过11指Office 2000,Office 2002和Office 2003。
'在顶部你的程序,你需要声明对象变量的具体应用的自动化。自动化微软其他,你需声明以下变量:
Dim otherApp As Other.Application
Dim otherDoc As Other.DocType
Dim otherSpecificObjects As Other.SpecificObjects

Then to open a new instance of Other:

Set otherApp = CreateObject("Other.Application")
'或使用现有的实例等:
Set otherApp = GetObject(,"Other.Application")

'例1:创建新的对象
'打开@R_696_10062@实例,创建一个新文件,做一些东西,保存并关闭文件,并退出幻灯片,你的代码是这样的:
Sub ExcelToNewPowerPoint()
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Create instance of PowerPoint
    Set PPApp = CreateObject("Powerpoint.Application")

    ' For automation to work,PowerPoint must be visible
    ' (alternatively,other extraordinary measures must be taken)
    PPApp.Visible = True

    ' Create a presentation
    Set PPPres = PPApp.presentations.Add

    ' Some PowerPoint actions work best in normal slide view
    PPApp.ActiveWindow.ViewType = ppViewSlide

    ' Add first slide to presentation
    Set PPSlide = PPPres.Slides.Add(1,ppLayouttitleOnly)

    ''---------------------
    '' Do Some stuff Here
    ''---------------------

    ' Save and close presentation
    With PPPres
        .SaveAs "C:\My Documents\MyPreso.ppt"
        .Close
    End With

    ' Quit PowerPoint
    PPApp.Quit

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing

End Sub

'例2:使用幻灯片对象
'使用活动的幻灯片在活动简报,你的程序看起来是这样的:
Sub ExcelToExisTingPowerPoint()
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Reference exisTing instance of PowerPoint
    Set PPApp = GetObject(,"Powerpoint.Application")

    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation

    ' Some PowerPoint actions work best in normal slide view
    PPApp.ActiveWindow.ViewType = ppViewSlide

    ' Reference active slide
    Set PPSlide = PPPres.Slides _
        (PPApp.ActiveWindow.SELEction.SlideRange.SlideIndeX) 

    ''---------------------
    '' Do Some stuff Here
    ''---------------------

    ' Save the presentation
    PPPres.Save

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing

End Sub

'例3:使用幻灯片对象如果它们存在的话
'以下步骤检查活动简报对象。如果发现现有的对象,它使用对象;否则需要创建新的对象。这增加了一个层面的防错的代码(见无误差操作)。
Sub ExcelToExisTingPowerPoint()
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Reference instance of PowerPoint
    On Error Resume Next
    ' check whether PowerPoint is running
    Set PPApp = GetObject(,"PowerPoint.Application")
    If PPApp Is Nothing Then
        ' PowerPoint is not running,create new instance
        Set PPApp = CreateObject("PowerPoint.Application")
        ' For automation to work,PowerPoint must be visible
        PPApp.Visible = True
    End If
    On Error GoTo 0

    ' Reference presentation and slide
    On Error Resume Next
    If PPApp.Windows.Count > 0 Then
        ' There is at least one presentation
        ' Use exisTing presentation
        Set PPPres = PPApp.ActivePresentation
        ' Use active slide
        Set PPSlide = PPPres.Slides _
            (PPApp.ActiveWindow.SELEction.SlideRange.SlideIndeX) 
    Else
        ' There are no presentations
        ' Create new presentation
        Set PPPres = PPApp.presentations.Add
        ' Add first slide
        Set PPSlide = PPPres.Slides.Add(1,ppLayoutBlank)
    End If
    On Error GoTo 0

    ' Some PowerPoint actions work best in normal slide view
    PPApp.ActiveWindow.ViewType = ppViewSlide

    ''---------------------
    '' Do Some stuff Here
    ''---------------------

    ' Save the presentation
    PPPres.Save

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing

End Sub

'早期与后期绑定
'大多数的例子在这个页面上使用早期绑定相关联的应用程序运行中的程序与其他应用。为探讨早期和后期绑定,指早期与后期绑定和联系,它提供了更全面的描述。

大佬总结

以上是大佬教程为你收集整理的Office应用程序与VBA应用开发全部内容,希望文章能够帮你解决Office应用程序与VBA应用开发所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: