简体   繁体   English

在 Excel (VBA) 中使用 PowerPoint 变量

[英]Use PowerPoint variable in Excel (VBA)

I have a PowerPoint Presentation and an Excel file.我有一个 PowerPoint 演示文稿和一个 Excel 文件。 In my PPT I use a public variable Public cnt As Long and the following two functions to add to cnt or subtract (as example):在我的 PPT 中,我使用公共变量Public cnt As Long和以下两个函数来添加到cnt或减去(例如):

Private Sub CommandButton1_Click()
cnt = cnt + 1
Me.CommandButton3.Caption = "cnt up = " & cnt
End Sub


Private Sub CommandButton2_Click()
cnt = cnt - 1
Me.CommandButton3.Caption = "cnt down = " & cnt
End Sub

Users will click on one of the two buttons during the PPT show which will add or subtract from the cnt variable.用户将在 PPT 展示期间单击两个按钮之一,这将增加或减少cnt变量。 So during the PPT show cnt may change from 1 to 2 then to 3 and so on.所以在PPT展示过程中, cnt可能会从1变成2然后变成3等等。

What I want is to document the value of cnt in an excel file.我想要的是在 excel 文件中记录cnt的值。 So for example during the PPT show value of cnt should be shown in cell "A1".因此,例如在 PPT 显示期间, cnt值应显示在单元格“A1”中。 Is this possible?这可能吗?

Here's a late binding example: (this goes into Powerpoint VBA)这是一个后期绑定示例:(这将进入 Powerpoint VBA)

Option Explicit

Public braX As Integer

Public Sub test()
  braX = 10
  Dim xlApp As Object
  Dim xlBooks As Object
  Dim xlBook As Object
  Dim xlSheet As Object
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True
  Set xlBooks = xlApp.workbooks
  Set xlBook = xlBooks.Add()
  Set xlSheet = xlBook.Worksheets(1)
  xlSheet.Range("A1") = braX
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM