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
excel vba excel-vba userform
add a comment |
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
excel vba excel-vba userform
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
add a comment |
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
excel vba excel-vba userform
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
excel vba excel-vba userform
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
add a comment |
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
add a comment |
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?
add a comment |
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
2
Dim Wb As Workbook
? There are no workbooks inThisWorkbook.Worksheets
. Either useDim Ws As Worksheets
andFor Each Ws In ThisWorkbook.Worksheets
or if you want to loop through workbooks useFor 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
add a comment |
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?
add a comment |
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?
add a comment |
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?
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?
edited Nov 8 at 19:31
answered Oct 4 at 14:14
CharlesPL
384
384
add a comment |
add a comment |
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
2
Dim Wb As Workbook
? There are no workbooks inThisWorkbook.Worksheets
. Either useDim Ws As Worksheets
andFor Each Ws In ThisWorkbook.Worksheets
or if you want to loop through workbooks useFor 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
add a comment |
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
2
Dim Wb As Workbook
? There are no workbooks inThisWorkbook.Worksheets
. Either useDim Ws As Worksheets
andFor Each Ws In ThisWorkbook.Worksheets
or if you want to loop through workbooks useFor 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
add a comment |
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
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
edited Oct 4 at 14:01
answered Oct 4 at 13:44
bmgh1985
6341133
6341133
2
Dim Wb As Workbook
? There are no workbooks inThisWorkbook.Worksheets
. Either useDim Ws As Worksheets
andFor Each Ws In ThisWorkbook.Worksheets
or if you want to loop through workbooks useFor 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
add a comment |
2
Dim Wb As Workbook
? There are no workbooks inThisWorkbook.Worksheets
. Either useDim Ws As Worksheets
andFor Each Ws In ThisWorkbook.Worksheets
or if you want to loop through workbooks useFor 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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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