+ Reply to Thread
Results 1 to 13 of 13

to use variables from macro of personal.xlsb

  1. #1
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    to use variables from macro of personal.xlsb

    Hi Everybody,



    I would like to use the variables in the activeworkbook from a macro placed in the personal.xlsb. I can run the macro "counter" with the command:

    Application.Run "personal.xlsb!counter"

    but after the check the values in the immediate window have no values.



    I tried so too:

    Application.Run "personal.xlsb!counter", fr, lr, fc, lc

    but at the end no values for fr,lr,fc,lc


    In the personal.xlsb have the sub:

    Public Sub counter(fr, fc, lr, lc)
    .....

    and the variables as Public declared.

    Thanks for your help.

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    Have you tried this?

    Please Login or Register  to view this content.
    Design everything to be as simple as possible, but no simpler.

  3. #3
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    Re: to use variables from macro of personal.xlsb

    I modified but can't call with:

    Application.Run "personal.xlsb!counter(ByRef fr, ByRef fc, ByRef lr, ByRef lc)"

    and
    with

    Application.Run "personal.xlsb!counter"

    also not

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    OK, I've checked and ByRef doesn't work. You have a few options as far as I can see:

    1. (easiest and most sensible) Copy the sub "counter" into the active workbook
    2. Rename your VBAProject in the active workbook (e.g. proj1), set up a reference in personal.xlsb (Tools > References), and change the values directly using the reference (e.g. proj1.fr = proj1.fr + 1)
    3. Create a function instead of a sub to output a new value, e.g.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    Re: to use variables from macro of personal.xlsb

    Hi,

    I tried to create a function instead of a sub but it doesn't work. I receive a fine values as a result of macro of personal.xlsb but it wont be added to the macro in the active sheet.

    Thanks for your Help

  6. #6
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    The example I gave above works. Could you post your full code, with [CODE][/CODE] tags around it?

  7. #7
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    Re: to use variables from macro of personal.xlsb

    Sub counter()



    lr2 = 1
    fr2 = 1
    lc2 = 1
    fc2 = 1

    If fc0 = 0 Or fc0 = "" Then

    For i = 1 To Columns.Count

    With ActiveSheet
    lr1 = .Cells(.Rows.Count, i).End(xlUp).Row
    If lr1 = 1 Then
    fr1 = 1
    Else
    fr1 = .Columns(i).Find("*", Cells(Rows.Count, i)).Row
    End If

    lc1 = .Cells(fr1, .Columns.Count).End(xlToLeft).Column
    If lc1 = 1 Then
    fc1 = 1
    Else
    fc1 = .Rows(fr1).Find("*", Cells(fr1, Columns.Count)).Column
    End If

    End With

    lr = IIf(lr2 > lr1, lr2, lr1)
    lr2 = lr
    fr = IIf(fr2 > fr1, fr1, fr2)
    fr2 = fr
    lc = IIf(lc2 > lc1, lc2, lc1)
    lc2 = lc
    fc = IIf(fc2 > fc1, fc1, fc2)
    fc2 = fc

    Next i

    Else

    With ActiveSheet
    lr = .Cells(.Rows.Count, Val(fc)).End(xlUp).Row
    If lr = 1 Then
    fr = 1
    Else
    fr = .Columns(Val(fc)).Find("*", Cells(Rows.Count, Val(fc))).Row
    End If

    lc = .Cells(fr, .Columns.Count).End(xlToLeft).Column



    End With
    End If

    End Sub

  8. #8
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    Re: to use variables from macro of personal.xlsb

    This code is in the personal.xlsb sheets and it should be called in an another workbook's modul

  9. #9
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    Please use [CODE[COLOR="#000000"]Please Login or Register to view this content.[/CODE]

    In personal.xlsb (I repaired some less-than-ideal coding as well):
    Please Login or Register  to view this content.
    I hope this helps.

  10. #10
    Registered User
    Join Date
    12-19-2017
    Location
    Germany
    MS-Off Ver
    MS Office Professional plus 2010
    Posts
    17

    Re: to use variables from macro of personal.xlsb

    Thank you for your Help!

  11. #11
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    Happy to help
    If that takes care of your original question, please select Thread Tools from the menu link above to mark this thread as SOLVED.
    To say thanks to the user(s) who contributed towards the solution, you can use the "Add Reputation" button on their helpful post(s).
    Thanks!

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: to use variables from macro of personal.xlsb

    Quote Originally Posted by Stormin' View Post
    OK, I've checked and ByRef doesn't work. You have a few options as far as I can see:
    It will work as long as you use a late bound variable to hold the Application instance (i.e. a Variant or Object type). So this will work
    Please Login or Register  to view this content.
    whereas this will not
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  13. #13
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: to use variables from macro of personal.xlsb

    Ooo, thanks xlnitwit, really handy to know

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. can't see macro moved from workbook into personal.xlsb
    By whburling in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2017, 01:26 AM
  2. [SOLVED] Personal.XLSB macro pasting into Personal.XLSB
    By davepoth in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2015, 07:40 PM
  3. Running a Personal.XLSB Macro From Within Another Personal.XLSB Macro
    By js0873 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-23-2015, 09:58 AM
  4. Replies: 0
    Last Post: 01-15-2015, 05:53 AM
  5. cannot run macro if personal.xlsb is hidden
    By illusionek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2014, 08:16 AM
  6. Add procedure to PERSONAL.XLSB with a macro from another workbook.
    By dimattia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2013, 10:21 AM
  7. DELETE the Personal.XLSB macro I created - can't get rid of it!
    By Cut2please in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2013, 07:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1