Hi Folks,
I am using the code below, which when run does the following:
The above all works as required.
However i want to carry out the same above actions if the workbook already open. I thought that the code allowed for this but it appears that i have made a mistake.
If the workbook "Team Leader.xls" is open then the following happens:
In Short i want to perform the above actions if the workbook "Team Leader.xls" is either opened or closed.
Here is my code:
Thanks
I am using the code below, which when run does the following:
- Opens workbook "Team Leader.xls" at specified location
Goes to Worksheets("Team Leader Screen") in the workbook
Carries out the functions in the with statement
Save and closes the workbook "Team Leader.xls"
The above all works as required.
However i want to carry out the same above actions if the workbook already open. I thought that the code allowed for this but it appears that i have made a mistake.
If the workbook "Team Leader.xls" is open then the following happens:
- Goes to workbook "Team Leader.xls" at specified location
Goes to Worksheets("Team Leader Screen") in the workbook
Carries out the functions in the with statement
A new pop up window appears asking if i would like to Save the workbook "Team Leader.xls"
In Short i want to perform the above actions if the workbook "Team Leader.xls" is either opened or closed.
Here is my code:
Code:
'*******Team Leader Screen***************
'This code opens the Worksheets("Team Leader Screen")located
'in Workbook "Team Leader.xls"
Dim TLS As Worksheet
Dim openflag As Boolean
openflag = False
For Each wb In Workbooks
wbname = wb.Name
If wbname = "Team Leader.xls" Then
openflag = True 'Workbook "Team Leader.xls" was already open
Windows(wbname).Activate
GoTo 100
End If
Next wb
Workbooks.Open Filename:="G:\Cwmbran-new\Warehouse\lean manu\Mike C\HandPack Time Sheet\On LIne\" & _
"Team Leader.xls"
100:
Set TLS = Worksheets("Team Leader Screen") 'This refers to worksheet in other workbook
With TLS
TLS.Range("G11") = TLS.Range("G8") 'Copies Completed Jobs to display in Team Leader Screen Previous Shift
TLS.Range("E11") = TLS.Range("E8") 'Copies Shift to display in Team Leader Screen Previous Shift
TLS.Range("E12") = TLS.Range("B28") 'Copies Total Discs Packed to display Team Leader Screen in Previous Shift
TLS.Range("E3") = ClearContents 'Team Leader
TLS.Range("E8") = ClearContents 'Shift
TLS.Range("G8") = ClearContents 'Completed Jobs
TLS.Range("B28") = ClearContents 'Total Discs
TLS.Range("H28") = ClearContents 'Total Quarantine Jobs
'TLS.ScreenListBox.Clear 'Empty the listbox
End With
If openflag = False Then 'Then Workbook "Shift Manager.xls" was not open so close it
Windows("Team Leader.xls").Close True '** or change to False if you do not want to save any changes - you need to decide
End If
'*******End Of Team Leader Screen*******
Thanks