none
Public Macro RRS feed

  • Question

  • I do not seem to be able to create a Public Variable

    Example:

    Public vVariable As String

    According to documentation this should work but doesn't. Any idea why not?

    Tuesday, February 18, 2014 5:39 PM

Answers

  • Problem Solved - apparently you cannot put a public or private variable inside a sub procedure - it must be declared externally - Thanks
    Wednesday, February 19, 2014 3:56 PM

All replies

  • Such a declaration should be entered in a standard module (the kind you create by selecting Insert > Module in the Visual Basic Editor), not in a class module such as ThisDocument.

    It should be placed at or near the top of the module, above all Subs and Functions.

    The variable will be available in all code within the same document.


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


    Tuesday, February 18, 2014 8:08 PM
  • why don't you try something like this

    Public vVariable  As String

    Sub main()

    vVariable = "Test"
    ThisDocument.Select
    Selection.TypeText (vVariablefsdf)

    End Sub


    VBA Programming Service


    Tuesday, February 18, 2014 8:09 PM
  • If Hans's information does not help you, please provide more information

    1. HOW does it not work? Are you getting an error? If yes, what?

    2. Where are you placing the variable declaration?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 19, 2014 6:30 AM
    Moderator
  • Problem Solved - apparently you cannot put a public or private variable inside a sub procedure - it must be declared externally - Thanks
    Wednesday, February 19, 2014 3:56 PM
  • Yes, that's correct :-) Glad you're up and running, now.

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 19, 2014 3:57 PM
    Moderator