Results 1 to 13 of 13

Thread: MACRO LOOp

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    6

    MACRO LOOp

    Hello

    I have multiple marcos and a userform "MULTIPLEMARCOS" with two textboxes.

    I would like to arrange a loop that could repeat on of the marcos as many time as it is required by user.

    Example:

    textbox1 - already created marco name
    textbox2 - amount of numbers that chosen marco in textbox1 should be repeated

    StartButton - should start the loop xx times entered in textbox2 of marco entered/chosen in textbox1.

    Can some one help me out and describe how it can be arranged please?

  2. #2
    Lively Member
    Join Date
    Jan 09
    Posts
    84

    Re: MACRO LOOp

    Do a For Loop. For i = 1 to textbox2.value ..... Next i

  3. #3
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    Re: MACRO LOOp

    you can try like
    Code:
    Private Sub CommandButton1_Click()
    For i = 1 To TextBox2
        CallByName UserForm1, textbox1,  VbMethod, i
    Next
    End Sub
    
    Sub cbn(c)
        CommandButton1.Caption = c
    End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: MACRO LOOp

    Quote Originally Posted by westconn1 View Post
    you can try like
    Code:
    Private Sub CommandButton1_Click()
    For i = 1 To TextBox2
        CallByName UserForm1, textbox1,  VbMethod, i
    Next
    End Sub
    
    Sub cbn(c)
        CommandButton1.Caption = c
    End Sub
    Thanks, but maybe I'm doing something wrong. I can't get a list of marcos in Textbox1.

    All my Macros are stored in NewMacros module as per below screen.
    Name:  map.jpg
Views: 46
Size:  7.6 KB

    is it even possible to do a check when user is typing the marco name and if it matches then marco from textbox1 will run i times entered in textbox2.

    I have also tried to do a combobox instead of textbox1, but still no resault. Does anyone have any ideas ?

  5. #5
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    989

    Re: MACRO LOOp

    Try stepping through the code in the attached to see if it gets you close (Excel 2010).
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    Re: MACRO LOOp

    Thanks, but maybe I'm doing something wrong. I can't get a list of marcos in Textbox1.
    why not use a listbox

    the sample code assumed the user would type a macro name into the textbox

    are your macros in the userform codepane or a module?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: MACRO LOOp

    Quote Originally Posted by westconn1 View Post
    why not use a listbox

    the sample code assumed the user would type a macro name into the textbox

    are your macros in the userform codepane or a module?
    Hello, yes all of my marcos are in the module (New Marcos).
    Yesterday I had a little progress. I managed to create a function GetMarcoList and update the textbox1 to combobox1 in my userform (MULTIPLEBKGS)

    Now everyting works almost like I wanted.

    **code**
    Sub STARTFORM ()
    MULTIPLEBKGS.Show
    End Sub.

    Private Sub cmdStart_Click()
    combobox1.MultiLine = True
    combobox1.Value = GetMacroList
    End Sub

    **

    The only this is that wrong that
    1) GetMarcoList function gets all the marcos from the whole project( all modules, *.xlam* and *.rsf* files) I require only all marcos from "New Marcos" module. Working to get this fixed

    2) I can't understand why all marco names are reflecting in combobox1 in one row separated with a comma.

    CITY_SEARCH,DRAY_INPUT,UPDATE,GTNEXUS,OPEN,Pattern,Mainframe1.Module.GetDataFromScreen,Mainframe1.Mo dule1.LoadConf,Mainframe1.Module.GetDataFromScreen

    // all m,arcos in combobox sholud be without comma at the end and reflect in combobox1 as each macro name per 1 row.

    P.S. By the way I'm not using Microsoft Office, I use WRQ Reflection ver 13.0

  8. #8
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    Re: MACRO LOOp

    as you do not show the code for getmacrolist it is hard to guess why it does not work as required
    try like

    Code:
    myarr = split(getmacrolist, ",")
    for i = 0 to ubound(myarr)
        combobox1.additem myarr(i)
    next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: MACRO LOOp

    Quote Originally Posted by westconn1 View Post

    Code:
    myarr = split(getmacrolist, ",")
    for i = 0 to ubound(myarr)
        combobox1.additem myarr(i)
    next


    Wow, that is genius,
    Million Thanks to.
    That works perfect

  10. #10
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: MACRO LOOp

    Hello again,

    I'm now tring to do lunch a marco from the MacName (combobox), but VB is reflecting with an error.
    I was tring to use

    'DoCmd.RunMacro (MacName.Value)"

    Can some one help me out pls

  11. #11
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    Re: MACRO LOOp

    i can not help with access specific methods (docmd)

    the example i posted above using callbyname would work
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    989

    Re: MACRO LOOp

    Something like this works in 2010:

    Code:
    strMac = "'macro loop.xlsm'!macAddNumbers"
                Application.Run strMac      'run the macro

  13. #13
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: MACRO LOOp

    Ok, will try both ways tomorrow at work and revert.

    Thanks to you all.

Posting Permissions

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