dsheard2015
Board Regular
- Joined
- May 10, 2016
- Messages
- 134
Hello,
I have a main folder which consists of many student folders and 1 Admin folder and this folder is moved to various locations on the network as needed. The student folders are originally named 1, 2, 3.... but when the class starts the folder names may be changed. Usually, the names match the names of each student but there is no pattern to what the instructor will use when renaming the folders. Admin will always remain the same. The workbooks within the student folders are all linked to the Admin workbook.
The example code below is located within the Admin workbook and is used to access the student workbook "1.xlsb", then finds the worksheet "AQC-Task Completion", then prints the range "A1:C41", and then returns back(Activates) to the Admin workbook.
The code works great as long as each student folder name remains 1, 2, 3.... but once the names are changed an error message pops up saying "the file can't be found..." which makes sense because the name was changed.
I have tried numerous things but can't seem to figure out how to get the name "1.xlsb" within the code to change dynamically when the folder name changes.
All help is greatly appreciated!
Dave
I have a main folder which consists of many student folders and 1 Admin folder and this folder is moved to various locations on the network as needed. The student folders are originally named 1, 2, 3.... but when the class starts the folder names may be changed. Usually, the names match the names of each student but there is no pattern to what the instructor will use when renaming the folders. Admin will always remain the same. The workbooks within the student folders are all linked to the Admin workbook.
The example code below is located within the Admin workbook and is used to access the student workbook "1.xlsb", then finds the worksheet "AQC-Task Completion", then prints the range "A1:C41", and then returns back(Activates) to the Admin workbook.
The code works great as long as each student folder name remains 1, 2, 3.... but once the names are changed an error message pops up saying "the file can't be found..." which makes sense because the name was changed.
I have tried numerous things but can't seem to figure out how to get the name "1.xlsb" within the code to change dynamically when the folder name changes.
All help is greatly appreciated!
Dave
Code:
Sub print_aqc_a_1_admin()
Dim WB As Workbook
On Error Resume Next
Set WB = Workbooks("[COLOR=#ff0000]1.xlsb[/COLOR]")
On Error GoTo 0
If WB Is Nothing Then
Set WB = Workbooks.Open(ThisWorkbook.Path & "\[COLOR=#ff0000]1.xlsb[/COLOR]")
Worksheets("AQC-Task Completion").Range("A1:C41").PrintOut
Application.Workbooks("ADMIN.xlsb").Activate
Else
Application.Workbooks("[COLOR=#ff0000]1.xlsb[/COLOR]").Activate
Worksheets("AQC-Task Completion").Range("A1:C41").PrintOut
Application.Workbooks("ADMIN.xlsb").Activate
End If
End Sub
Last edited: