Teladianium
New Member
- Joined
- Apr 10, 2012
- Messages
- 15
Hi Guys,
Quick disclaimer, Im not great at the code and am learning by plagiarism. so I have the sub "ListWorkbooks" which works great at providing a list of all the open wb. i am looking for a "buzzword" in the wb names. In this case, I am looking for "STAN", the rest of the name is made up with unknown variable info. What I want to do is assign the workbook name to the STAN variable in the "assignWB" sub so I can select or activate that wb to pull data and dump in in another wb (which will be another buzz worded open wb).
The issue I get is in the opening wb line "Windows(STANWB).Select" i also tryed Workbooks(STANWB).Select and .Activate. i even tried Application.Workbooks which it didn't like either. The msgbox retuns the corect wb name complete with the file ext. any help really appriciated.
Sub ListWorkbooks()
Sheets("Open workbooks").Range("A1").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Dim Rng As Range
Dim WorkRng As Range
Dim WTWB
On Error Resume Next
Set WorkRng = ActiveWorkbook.Sheets("Open workbooks").Range("A1")
xNum1 = Application.Workbooks.Count
For i = 1 To xNum1
xNum2 = Application.Workbooks(i).Sheets.Count
WorkRng.Offset(i - 1, 0).Value = Application.Workbooks(i).Name
If Application.Workbooks(i).Find(what:="STAN") = True Then WTWB = Application.Workbooks(i).Name
For j = 1 To xNum2
WorkRng.Offset(i - 1, j).Value = Application.Workbooks(i).Sheets(j).Name
Next
Next
End Sub
Sub assignWB()
Dim STANWB
ActiveWorkbook.Sheets("Open workbooks").Select
Range("A:A").Find(what:="STAN").Select
STANWB = ActiveCell.Value
MsgBox STANWB
Windows(STANWB).Select
MsgBox STANWB
End Sub
Below just an exaple of the returned data
Quick disclaimer, Im not great at the code and am learning by plagiarism. so I have the sub "ListWorkbooks" which works great at providing a list of all the open wb. i am looking for a "buzzword" in the wb names. In this case, I am looking for "STAN", the rest of the name is made up with unknown variable info. What I want to do is assign the workbook name to the STAN variable in the "assignWB" sub so I can select or activate that wb to pull data and dump in in another wb (which will be another buzz worded open wb).
The issue I get is in the opening wb line "Windows(STANWB).Select" i also tryed Workbooks(STANWB).Select and .Activate. i even tried Application.Workbooks which it didn't like either. The msgbox retuns the corect wb name complete with the file ext. any help really appriciated.
Sub ListWorkbooks()
Sheets("Open workbooks").Range("A1").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Dim Rng As Range
Dim WorkRng As Range
Dim WTWB
On Error Resume Next
Set WorkRng = ActiveWorkbook.Sheets("Open workbooks").Range("A1")
xNum1 = Application.Workbooks.Count
For i = 1 To xNum1
xNum2 = Application.Workbooks(i).Sheets.Count
WorkRng.Offset(i - 1, 0).Value = Application.Workbooks(i).Name
If Application.Workbooks(i).Find(what:="STAN") = True Then WTWB = Application.Workbooks(i).Name
For j = 1 To xNum2
WorkRng.Offset(i - 1, j).Value = Application.Workbooks(i).Sheets(j).Name
Next
Next
End Sub
Sub assignWB()
Dim STANWB
ActiveWorkbook.Sheets("Open workbooks").Select
Range("A:A").Find(what:="STAN").Select
STANWB = ActiveCell.Value
MsgBox STANWB
Windows(STANWB).Select
MsgBox STANWB
End Sub
Below just an exaple of the returned data
Report_builder.xlsx | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | book1.xlsm | Sheet 1 | Sheet 2 | Sheet 3 | Sheet 4 | |||
2 | wbrandom_476_STAN_complete_roandom.xlsm | Info | Sheet 2 | Sheet 3 | Sheet 4 | |||
3 | some_other_WB.xlsm | Sheet 1 | Sheet 2 | Sheet 3 | Sheet 4 | |||
4 | And_another.xlsm | Sheet 1 | Sheet 2 | Sheet 3 | Sheet 4 | |||
5 | ||||||||
6 | ||||||||
Sheet1 |