Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换vba powerpoint中的变量_Vba_Excel_Variables_Powerpoint - Fatal编程技术网

替换vba powerpoint中的变量

替换vba powerpoint中的变量,vba,excel,variables,powerpoint,Vba,Excel,Variables,Powerpoint,我正在尝试替换并保存VBA Powerpoint中的整数 我在1子例程中有一个名为projectId的变量。目前,变量设置为617。在另一个子例程中,我正在运行一个用户输入方法,该方法提示用户输入一个新的projectId,并存储新的projectId以替换“617”。唯一的问题是,当我关闭PowerPoint并重新打开它时,projectId变为0 对于本例,是否有任何方法将代码projectd=617物理替换为projectd=699 下面是我正在使用的代码,请注意,projId是一个全局验

我正在尝试替换并保存VBA Powerpoint中的整数

我在1子例程中有一个名为projectId的变量。目前,变量设置为617。在另一个子例程中,我正在运行一个用户输入方法,该方法提示用户输入一个新的projectId,并存储新的projectId以替换“617”。唯一的问题是,当我关闭PowerPoint并重新打开它时,projectId变为0

对于本例,是否有任何方法将代码
projectd=617
物理替换为
projectd=699

下面是我正在使用的代码,请注意,
projId
是一个全局验证:

    Dim projId As Integer


如果在
ChangeProjID()
之后调用
CommentConnect()
,则行
projId=617
将覆盖用户在
ChangeProjID()中输入的任何值

我看到了一些解决这个问题的方法

  • ChangeProjID()
    的签名更改为:
    函数ChangeProjID()为整数

    然后将
    注释中的行更改为:

    projId=ChangeProjID()
  • CommentConnect()
    中的行更改为:
    如果projId=0,则使用此值作为默认值
  • 对于选项1,完整、更改的代码如下所示:

    Function ChangeProjID() As Integer
        Dim strProjId As String
        Dim intProjId As Integer
    
        strProjId = InputBox("Enter the Project ID given by example:", "Project ID Input")
    
        On Error GoTo NotValidID
        intProjId = CInt(strProjId)
        MsgBox " Your new project ID will be set to " & intProjId & " until changed again"
        ChangeProjID = intProjId
    
        Exit Sub
    
    NotValidID:
        MsgBox " You must enter a valid integer"
    End Sub
    
    Public Sub CommentConnect(control As IRibbonControl)
        Dim URL As String
        projId = ChangeProjID
        URL = "example.com/prID="
        ActivePresentation.FollowHyperlink (URL & projId)
    End Sub
    
    选项2的完整、变更代码为:

    Public Sub CommentConnect(control As IRibbonControl)
    
    
        Dim URL As String
        if projId = 0 then
          projId = 617           'use project 617 as the default
        End If
        URL = "example.com/prID="
    
    
        ActivePresentation.FollowHyperlink (URL & projId)
    
    End Sub
    
    请注意,无论您做什么,
    projId
    在您第一次打开PPTX时将默认为
    0
    ——这是变量的性质,在应用程序启动时,它们都有一个默认值,直到设置为其他值

    如果需要,可以创建某种机制,将
    projId
    存储在非易失性内存中(文本文件、注册表、PPT第一张幻灯片上的隐藏(背景色=前景色)字段等)。或者您可以对
    projId
    进行某种初始化,以便在启动代码时,它总是被设置为某个已知的非零值,但它不会自己保留最后的设置值。
    CommentConnect()
    如果在
    ChangeProjID()
    之后调用
    CommentConnect()
    ,行
    projId=617
    将覆盖用户在
    ChangeProjID()
    中输入的任何值

    我看到了一些解决这个问题的方法

  • ChangeProjID()
    的签名更改为:
    函数ChangeProjID()为整数

    然后将
    注释中的行更改为:

    projId=ChangeProjID()
  • CommentConnect()
    中的行更改为:
    如果projId=0,则使用此值作为默认值
  • 对于选项1,完整、更改的代码如下所示:

    Function ChangeProjID() As Integer
        Dim strProjId As String
        Dim intProjId As Integer
    
        strProjId = InputBox("Enter the Project ID given by example:", "Project ID Input")
    
        On Error GoTo NotValidID
        intProjId = CInt(strProjId)
        MsgBox " Your new project ID will be set to " & intProjId & " until changed again"
        ChangeProjID = intProjId
    
        Exit Sub
    
    NotValidID:
        MsgBox " You must enter a valid integer"
    End Sub
    
    Public Sub CommentConnect(control As IRibbonControl)
        Dim URL As String
        projId = ChangeProjID
        URL = "example.com/prID="
        ActivePresentation.FollowHyperlink (URL & projId)
    End Sub
    
    选项2的完整、变更代码为:

    Public Sub CommentConnect(control As IRibbonControl)
    
    
        Dim URL As String
        if projId = 0 then
          projId = 617           'use project 617 as the default
        End If
        URL = "example.com/prID="
    
    
        ActivePresentation.FollowHyperlink (URL & projId)
    
    End Sub
    
    请注意,无论您做什么,
    projId
    在您第一次打开PPTX时将默认为
    0
    ——这是变量的性质,在应用程序启动时,它们都有一个默认值,直到设置为其他值


    如果需要,可以创建某种机制,将
    projId
    存储在非易失性内存中(文本文件、注册表、PPT第一张幻灯片上的隐藏(背景色=前景色)字段等)。或者您可以对
    projId
    进行某种初始化,以便在启动代码时,它总是被设置为某个已知的非零值,但它不会自己保留最后一个设置值。

    弗里曼的想法是正确的。。。将值存储在非易失性存储器中

    幸运的是,PowerPoint有一个功能非常适合这一点:标签

    With ActivePresentation
      .Tags.Add "ProjectID", Cstr(intProjID)
    End With
    
    intProjID的字符串版本现在是附加到表示对象的永久“标记”。要检索它,请执行以下操作:

    MsgBox ActivePresentation.Tags("ProjectID")
    

    每个演示文稿、幻灯片和形状都可以有任意多个标签。

    弗里曼的想法是正确的。。。将值存储在非易失性存储器中

    幸运的是,PowerPoint有一个功能非常适合这一点:标签

    With ActivePresentation
      .Tags.Add "ProjectID", Cstr(intProjID)
    End With
    
    intProjID的字符串版本现在是附加到表示对象的永久“标记”。要检索它,请执行以下操作:

    MsgBox ActivePresentation.Tags("ProjectID")
    

    每个演示文稿、幻灯片和形状都可以有任意数量的标签。

    谢谢FreeMan。这声音怎么样。。。如果我在第一个页面上创建一个文本框,其中包含userInput输入的projId,那么我可以用这种方式保存id并从子例程中引用它吗?绝对可以!这就是PPT第一张幻灯片上的隐藏(背景色=前景色)字段所指的内容s关于使用
    .tag
    的建议也会很有效。谢谢FreeMan。这声音怎么样。。。如果我在第一个页面上创建一个文本框,其中包含userInput输入的projId,那么我可以用这种方式保存id并从子例程中引用它吗?绝对可以!这就是PPT第一张幻灯片上的隐藏(背景色=前景色)字段所指的内容Steve关于使用
    .tag
    的建议也会很有效。Steve,我如何从vba内部引用该标记?它很有效!!非常感谢各位!你们都是救生员。我希望我能给你们两个一张支票!Steve,我如何从vba内部引用该标记?它起作用了!!非常感谢各位!你们都是救生员。我希望我能给你们两个一张支票!