I am trying to replace and save an integer in VBA Powerpoint.
I have a variable in 1 Subroutine named projectId. At the moment, the variable is set to 617. In another subroutine I am running a user input method that prompts the user for a new projectId and stores the new projectId to replace the "617". The only issue is the projectId go to 0 when I close the PowerPoint and reopen it.
Is there any way to physically replace the code projectId = 617
with projectId = 699
for this example.
Below is the code Im working with, notice that projId
is a global veriable:
Dim projId As Integer
Sub ChangeProjID()
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)
projId = intProjId
MsgBox " Your new project ID will be set to " & intProjId & " until changed again"
Exit Sub
NotValidID:
MsgBox " You must enter a valid integer"
End Sub
Public Sub CommentConnect(control As IRibbonControl)
Dim URL As String
projId = 617
URL = "example.com/prID="
ActivePresentation.FollowHyperlink (URL & projId)
End Sub
FreeMan's got the right idea ... store the value in non-volatile memory.
Luckily, PowerPoint has a feature that's perfect for this: Tags.
The string version of intProjID is now a permanent "tag" attached to the presentation object. To retrieve it:
Each presentation, slide and shape can have pretty much as many of these tags as you like.