Userform to navigate and select another open workbook











up vote
0
down vote

favorite












I have a small program VBA which is fact a userform which allow me to display all the existing worksheet of one open workbook on which I am working. Via this userform I can select another sheet and by clicking the sheet via this userform, it reorients me to the desired worksheet.
Now I tried to modifiy a bit of part of this program in order to do it the same but with all my open workbooks. It means if I have several workbook open, I would like that my userform allows me to display all the existing open workbook and by selecting the desired workbook via the userform, it reorients me to this workbook (it means that the selected workbook in the userform is activated and selected). The problem is when I run the code, I have an error message 424 VBA Run-time error '424' Object Required Error…



PS:really sorry for the format of my Code but I do not manage to put it in the right format..



Thanks in advance for your help
Xavi



Here please find the original code which works for userform related to worksheet (this one works):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim sht As Worksheet

Do
n = n + 1
Me.ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count

End Sub


Here please find the modified code for userform related to workbook (this one does not works: run time error 424):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim Wb As Workbook

Do
n = n + 1
Me.ListBox1.AddItem Workbooks(n).Name
Loop Until n = Worksbooks.Count

End Sub









share|improve this question
























  • You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
    – T.M.
    Oct 4 at 14:15






  • 1




    Thanks a lot, it is exactly what I was looking for...
    – Xavi
    Oct 5 at 4:58















up vote
0
down vote

favorite












I have a small program VBA which is fact a userform which allow me to display all the existing worksheet of one open workbook on which I am working. Via this userform I can select another sheet and by clicking the sheet via this userform, it reorients me to the desired worksheet.
Now I tried to modifiy a bit of part of this program in order to do it the same but with all my open workbooks. It means if I have several workbook open, I would like that my userform allows me to display all the existing open workbook and by selecting the desired workbook via the userform, it reorients me to this workbook (it means that the selected workbook in the userform is activated and selected). The problem is when I run the code, I have an error message 424 VBA Run-time error '424' Object Required Error…



PS:really sorry for the format of my Code but I do not manage to put it in the right format..



Thanks in advance for your help
Xavi



Here please find the original code which works for userform related to worksheet (this one works):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim sht As Worksheet

Do
n = n + 1
Me.ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count

End Sub


Here please find the modified code for userform related to workbook (this one does not works: run time error 424):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim Wb As Workbook

Do
n = n + 1
Me.ListBox1.AddItem Workbooks(n).Name
Loop Until n = Worksbooks.Count

End Sub









share|improve this question
























  • You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
    – T.M.
    Oct 4 at 14:15






  • 1




    Thanks a lot, it is exactly what I was looking for...
    – Xavi
    Oct 5 at 4:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a small program VBA which is fact a userform which allow me to display all the existing worksheet of one open workbook on which I am working. Via this userform I can select another sheet and by clicking the sheet via this userform, it reorients me to the desired worksheet.
Now I tried to modifiy a bit of part of this program in order to do it the same but with all my open workbooks. It means if I have several workbook open, I would like that my userform allows me to display all the existing open workbook and by selecting the desired workbook via the userform, it reorients me to this workbook (it means that the selected workbook in the userform is activated and selected). The problem is when I run the code, I have an error message 424 VBA Run-time error '424' Object Required Error…



PS:really sorry for the format of my Code but I do not manage to put it in the right format..



Thanks in advance for your help
Xavi



Here please find the original code which works for userform related to worksheet (this one works):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim sht As Worksheet

Do
n = n + 1
Me.ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count

End Sub


Here please find the modified code for userform related to workbook (this one does not works: run time error 424):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim Wb As Workbook

Do
n = n + 1
Me.ListBox1.AddItem Workbooks(n).Name
Loop Until n = Worksbooks.Count

End Sub









share|improve this question















I have a small program VBA which is fact a userform which allow me to display all the existing worksheet of one open workbook on which I am working. Via this userform I can select another sheet and by clicking the sheet via this userform, it reorients me to the desired worksheet.
Now I tried to modifiy a bit of part of this program in order to do it the same but with all my open workbooks. It means if I have several workbook open, I would like that my userform allows me to display all the existing open workbook and by selecting the desired workbook via the userform, it reorients me to this workbook (it means that the selected workbook in the userform is activated and selected). The problem is when I run the code, I have an error message 424 VBA Run-time error '424' Object Required Error…



PS:really sorry for the format of my Code but I do not manage to put it in the right format..



Thanks in advance for your help
Xavi



Here please find the original code which works for userform related to worksheet (this one works):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim sht As Worksheet

Do
n = n + 1
Me.ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count

End Sub


Here please find the modified code for userform related to workbook (this one does not works: run time error 424):



Sub UserForm_Initialize()
Dim n As Long
Dim msg As String
Dim i As Long
Dim s As String
Dim Wb As Workbook

Do
n = n + 1
Me.ListBox1.AddItem Workbooks(n).Name
Loop Until n = Worksbooks.Count

End Sub






excel vba excel-vba userform






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 4 at 13:44









Pᴇʜ

19.1k42650




19.1k42650










asked Oct 4 at 13:33









Xavi

366




366












  • You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
    – T.M.
    Oct 4 at 14:15






  • 1




    Thanks a lot, it is exactly what I was looking for...
    – Xavi
    Oct 5 at 4:58


















  • You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
    – T.M.
    Oct 4 at 14:15






  • 1




    Thanks a lot, it is exactly what I was looking for...
    – Xavi
    Oct 5 at 4:58
















You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
– T.M.
Oct 4 at 14:15




You have a typo in the closing loop statement, should be as follows: Loop Until n = Workbooks.Count ( instead of "Worksbooks" ).
– T.M.
Oct 4 at 14:15




1




1




Thanks a lot, it is exactly what I was looking for...
– Xavi
Oct 5 at 4:58




Thanks a lot, it is exactly what I was looking for...
– Xavi
Oct 5 at 4:58












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










May I propose a simple for loop ?



Dim i As Long
For i = 1 To Application.Workbooks.Count
Debug.Print Application.Workbooks(i).Name
Next


Then, if you have different instances of Excel (different Application objects then the one your Userform came from), this become a little bit more complex. (This is probably not the case if you are working in Excel 2010 or newer). But, if this is the case, it requires a couple of Win32 API calls and some insights on the "windows" of Excel. I've found my answers here in the past : Can VBA Reach Across Instances of Excel?






share|improve this answer






























    up vote
    1
    down vote













    If there is no reason for the actual number to be parsed in your code, then why not just loop the sheets directly?



    Sub UserForm_Initialize()
    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
    Me.ListBox1.AddItem ws.Name
    Next ws

    End Sub





    share|improve this answer



















    • 2




      Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
      – Pᴇʜ
      Oct 4 at 13:46












    • Half asleep and missed that. I'll fix it
      – bmgh1985
      Oct 4 at 14:00











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52648092%2fuserform-to-navigate-and-select-another-open-workbook%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    May I propose a simple for loop ?



    Dim i As Long
    For i = 1 To Application.Workbooks.Count
    Debug.Print Application.Workbooks(i).Name
    Next


    Then, if you have different instances of Excel (different Application objects then the one your Userform came from), this become a little bit more complex. (This is probably not the case if you are working in Excel 2010 or newer). But, if this is the case, it requires a couple of Win32 API calls and some insights on the "windows" of Excel. I've found my answers here in the past : Can VBA Reach Across Instances of Excel?






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      May I propose a simple for loop ?



      Dim i As Long
      For i = 1 To Application.Workbooks.Count
      Debug.Print Application.Workbooks(i).Name
      Next


      Then, if you have different instances of Excel (different Application objects then the one your Userform came from), this become a little bit more complex. (This is probably not the case if you are working in Excel 2010 or newer). But, if this is the case, it requires a couple of Win32 API calls and some insights on the "windows" of Excel. I've found my answers here in the past : Can VBA Reach Across Instances of Excel?






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        May I propose a simple for loop ?



        Dim i As Long
        For i = 1 To Application.Workbooks.Count
        Debug.Print Application.Workbooks(i).Name
        Next


        Then, if you have different instances of Excel (different Application objects then the one your Userform came from), this become a little bit more complex. (This is probably not the case if you are working in Excel 2010 or newer). But, if this is the case, it requires a couple of Win32 API calls and some insights on the "windows" of Excel. I've found my answers here in the past : Can VBA Reach Across Instances of Excel?






        share|improve this answer














        May I propose a simple for loop ?



        Dim i As Long
        For i = 1 To Application.Workbooks.Count
        Debug.Print Application.Workbooks(i).Name
        Next


        Then, if you have different instances of Excel (different Application objects then the one your Userform came from), this become a little bit more complex. (This is probably not the case if you are working in Excel 2010 or newer). But, if this is the case, it requires a couple of Win32 API calls and some insights on the "windows" of Excel. I've found my answers here in the past : Can VBA Reach Across Instances of Excel?







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 8 at 19:31

























        answered Oct 4 at 14:14









        CharlesPL

        384




        384
























            up vote
            1
            down vote













            If there is no reason for the actual number to be parsed in your code, then why not just loop the sheets directly?



            Sub UserForm_Initialize()
            Dim ws As Worksheet

            For Each ws In ThisWorkbook.Worksheets
            Me.ListBox1.AddItem ws.Name
            Next ws

            End Sub





            share|improve this answer



















            • 2




              Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
              – Pᴇʜ
              Oct 4 at 13:46












            • Half asleep and missed that. I'll fix it
              – bmgh1985
              Oct 4 at 14:00















            up vote
            1
            down vote













            If there is no reason for the actual number to be parsed in your code, then why not just loop the sheets directly?



            Sub UserForm_Initialize()
            Dim ws As Worksheet

            For Each ws In ThisWorkbook.Worksheets
            Me.ListBox1.AddItem ws.Name
            Next ws

            End Sub





            share|improve this answer



















            • 2




              Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
              – Pᴇʜ
              Oct 4 at 13:46












            • Half asleep and missed that. I'll fix it
              – bmgh1985
              Oct 4 at 14:00













            up vote
            1
            down vote










            up vote
            1
            down vote









            If there is no reason for the actual number to be parsed in your code, then why not just loop the sheets directly?



            Sub UserForm_Initialize()
            Dim ws As Worksheet

            For Each ws In ThisWorkbook.Worksheets
            Me.ListBox1.AddItem ws.Name
            Next ws

            End Sub





            share|improve this answer














            If there is no reason for the actual number to be parsed in your code, then why not just loop the sheets directly?



            Sub UserForm_Initialize()
            Dim ws As Worksheet

            For Each ws In ThisWorkbook.Worksheets
            Me.ListBox1.AddItem ws.Name
            Next ws

            End Sub






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 4 at 14:01

























            answered Oct 4 at 13:44









            bmgh1985

            6341133




            6341133








            • 2




              Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
              – Pᴇʜ
              Oct 4 at 13:46












            • Half asleep and missed that. I'll fix it
              – bmgh1985
              Oct 4 at 14:00














            • 2




              Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
              – Pᴇʜ
              Oct 4 at 13:46












            • Half asleep and missed that. I'll fix it
              – bmgh1985
              Oct 4 at 14:00








            2




            2




            Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
            – Pᴇʜ
            Oct 4 at 13:46






            Dim Wb As Workbook? There are no workbooks in ThisWorkbook.Worksheets. Either use Dim Ws As Worksheets and For Each Ws In ThisWorkbook.Worksheets or if you want to loop through workbooks use For Each Wb In Workbooks
            – Pᴇʜ
            Oct 4 at 13:46














            Half asleep and missed that. I'll fix it
            – bmgh1985
            Oct 4 at 14:00




            Half asleep and missed that. I'll fix it
            – bmgh1985
            Oct 4 at 14:00


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52648092%2fuserform-to-navigate-and-select-another-open-workbook%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check