Results 1 to 10 of 604

Thread: Appendix-Thread-Evaluate-Range-(-Codes-for-other-Threads-HTML-Tables-etc-)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    In support of this main Forum post:
    http://www.eileenslounge.com/viewtop...297074#p297074 http://http://www.eileenslounge.com/viewtop...297074#p297074
    First overcomplicated Solution

    Hello
    Quote Originally Posted by adeel1 post_id=297073 time=1657888942 user_id=7609
    .... in real these values will go to another WBK.
    :::
    or now just one question, "public" will always declare for userfrom means storing value either within WBK or for Other WBK.
    Quote Originally Posted by HansV post_id=297076 time=1657891714 user_id=53
    Public means that the variable will be "known" in all code modules of the same workbook, but not in code modules in other open workbooks. .
    If Public variables are being the things that go in a normal code module, as I think they are, technically, or officially, or words to that effect, then that is the case that they won’t be known in other workbooks.
    In other words, for the purposes of what is going on here, it means you will need to be storing them in the same workbook, as Hans said, and how he demonstrated.

    However, you can do something that technically is not involving Public variables, but as far as I can tell, to all intents and purposes, is in effect the same thing as if you could have those Public variable in a different workbook.

    The short story is:
    Instead of putting the two public variables in a standard normal code module, ( in the same workbook) as Hans did, we can put them in any Class object code module in any open workbook. Technically they are not called Public variables. They are , I think, properties of the instantiated Class object, and we can access them, in the usual way that we access properties of an object.

    The full story
    PurseWayDoughPublicVariables.xls

    I have another workbook uploaded, PurseWayDoughPublicVariables.xls . That is just to hold these variables. (I will call them “pseudo” Public variables, just because I feel like it ),
    I can put them in any Class object code module, but just for fun, I will put C1 in a worksheet code module, and C2 in the ThisWorkbook code module.

    So, this is what Hans did, public variables in a standard normal module like
    Standard module, Module1
    Code:
     Public C1 As String
    Public C2 As String
    Instead of doing that , I will put those variables in Class object code modules in PurseWayDoughPublicVariables.xls, like this:

    Worksheet code module, Sheet1
    Code:
     Public C1 As String
    '
    '
    '
    Sub PhilC1(ByVal Wrd As String)
     Let C1 = Wrd
    End Sub
    Workbook code module, ThisWorkbook
    Code:
     Public C2 As String
    '
    '
    '
    Sub PhilC2(ByVal Wrd As String)
     Let C2 = Wrd
    End Sub
    *** The reason for those extra macros that fill the variables will be apparent shortly….
    _.__________________________________-

    Sample for Eli.xlsm
    I need to modify now the workbook uploaded by Hans, in 3 main ways:
    _(i) I don’t need the two public variables in a standard normal code module anymore
    _(ii) I need to modify slightly how I reference the variables
    Code:
     Sub Fi_l()
        'Act_ive
     'Let Range("A2").Resize(10).Value = C1
     Let Range("A2").Resize(10).Value = Workbooks("PurseWayDoughPublicVariables.xls").Worksheets("Sheet1").C1
     'let Range("B2").Resize(10).Value = C2
     Let Range("B2").Resize(10).Value = Workbooks("PurseWayDoughPublicVariables.xls").C2
    End Sub
    _(iii) Filling the variable is slightly more tricky. As far as I know, I can’t easily directly fill them from a macro in Sample for Eli.xlsm. - ***Edit: not true - see next post!! But I can run those extra macros*** that fill the variables, from Sample for Eli.xlsm
    So to do that I modify the coding in the UserForm thus, ( for the purposes of this demo, I assume the two workbooks are stored in the same place):
    Code:
     Private Sub CommandButton1_Click()
        Select Case Me.CheckBox1
         Case True
          'C1 = "yes"
          Application.Run Macro:="'" & ThisWorkbook.Path & "\" & "PurseWayDoughPublicVariables.xls'!Sheet1.PhilC1", Arg1:="Yus"
        End Select
        Select Case Me.CheckBox2
         Case True
          'C2 = "yes"
          Application.Run Macro:="'" & ThisWorkbook.Path & "\" & "PurseWayDoughPublicVariables.xls'!ThisWorkbook.PhilC2", Arg1:="Ja"
        End Select
     Unload Me
     Call Sheet2.Fi_l
    End Sub
    _.____

    That’s it. So download both files, store them in the same place, and then the coding in Sample for Eli.xlsm should work as before. The only difference is that you are using the “pseudo” public variables in the workbook PurseWayDoughPublicVariables.xls

    _.________________________________________________ _____________________


    I have not seen this use of “pseudo” public variables much before, so there may be some reason I don’t know about why they should not be used??
    But I use them myself sometimes, and so far I have never seen them behave any differently to “proper” public variables

    ( I would just finally say that I don’t use public variables much myself, pseudo or otherwise, if I can find another way to do what I want. I don’t like public variables myself. For one reason: I find they have an annoying habit of getting emptied sometimes. )



    Alan


    Ref
    https://stackoverflow.com/questions/...ther-workbook#
    https://excelfox.com/forum/showthrea...ll=1#post11870
    https://stackoverflow.com/questions/...12342#59812342
    https://www.mrexcel.com/board/thread.../#post-4629654
    Attached Files Attached Files

Similar Threads

  1. Testing Concatenating with styles
    By DocAElstein in forum Test Area
    Replies: 2
    Last Post: 12-20-2020, 02:49 AM
  2. testing
    By Jewano in forum Test Area
    Replies: 7
    Last Post: 12-05-2020, 03:31 AM
  3. Replies: 18
    Last Post: 03-17-2019, 06:10 PM
  4. Concatenating your Balls
    By DocAElstein in forum Excel Help
    Replies: 26
    Last Post: 10-13-2014, 02:07 PM
  5. Replies: 1
    Last Post: 12-04-2012, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •