none
VBA Microsoft Programming Accessing Variables across slides RRS feed

  • Question

  • I am trying to access a variable from slide 2 in a later slide

    in the slide 2 code I have declared the variable as public

    1. Public UserName As String

    then I have set the value of this inside my button click function

    1. Public Sub SaveName_Click()
    2. UserName = TextBox1.Value
    3. End Sub

    I am trying to access the variable on a later slide by using

    1. Slide2.UserName

    However I am having no luck, can anyone advise me on where I am going wrong?

    Thank you in advance

    Friday, June 26, 2020 12:12 PM

Answers

  • Code isn't tied to a specific slide. It belongs to the presentation as a whole. So you can refer to the variable by its name only: UserName in your example (in a procedure or function, of course).

    Regards, Hans Vogelaar (https://www.eileenslounge.com)

    • Marked as answer by TheOuz Friday, June 26, 2020 3:17 PM
    Friday, June 26, 2020 2:03 PM
  • Worked it out myself. I needed to declare the variable in a module rather than a microsoft Powerpoint Object, thank you for the reply.
    • Marked as answer by TheOuz Friday, June 26, 2020 3:17 PM
    Friday, June 26, 2020 3:17 PM

All replies

  • Code isn't tied to a specific slide. It belongs to the presentation as a whole. So you can refer to the variable by its name only: UserName in your example (in a procedure or function, of course).

    Regards, Hans Vogelaar (https://www.eileenslounge.com)

    • Marked as answer by TheOuz Friday, June 26, 2020 3:17 PM
    Friday, June 26, 2020 2:03 PM
  • I have tried this but no value is being passed through. Any ideas on what could be going wrong?
    • Edited by TheOuz Friday, June 26, 2020 2:58 PM
    Friday, June 26, 2020 2:58 PM
  • Worked it out myself. I needed to declare the variable in a module rather than a microsoft Powerpoint Object, thank you for the reply.
    • Marked as answer by TheOuz Friday, June 26, 2020 3:17 PM
    Friday, June 26, 2020 3:17 PM