Roggy_Swiss
New Member
- Joined
- May 30, 2013
- Messages
- 10
Hi,
I have a code taking data of a one workbook (Workbook1) and putting the specified data into another workbook ("MasterFile" {Workbook2}). The code works fine if the MasterFile is NOT open, because the code works on the workbooks.open event.
What I would like is, when the MasterFile is ALREADY open, then populate a MsgBox saying something like "Workbook currently in use, please contact HR and try again later" AND exit the whole sub and return to the original data sheet (Workbook1). Please also note that the Workbook2 is password protected. I know this has probably been asked before, but I cannot find an answer corresponding to this specific issue.
Here is what I have now (not all of it, but the relevant code):
Private Sub CommandButton1_Click()
Dim MasterFile As Workbook
Set MasterFile = Workbooks.Open("G:\Time Tracking\FileName.xlsx", Password:="XY")
Worksheets("MasterFileHours").Select
Worksheets("MasterFileHours").Range("A1").Select
RowCount = Worksheets("MasterFileHours").Range("A1").CurrentRegion.Rows.Count
Application.ScreenUpdating = False
Application.Visible = False
With Worksheets("MasterFileHours").Range("A1")
.Offset(RowCount, 0).Value = WeekNo
.Offset(RowCount, 1).Value = xDate
.Offset(RowCount, 2).Value = EOWEEK
.Offset(RowCount, 3).Value = Employee
.Offset(RowCount, 4).Value = HoursEffective
.Offset(RowCount, 5).Value = HoursTarget
.Offset(RowCount, 6).Value = OverUnder
.Offset(RowCount, 7).Value = Pot60Increase
.Offset(RowCount, 8).Value = Pot60Decrease
End With
MasterFile.Save
MasterFile.Close
End Sub
THANKS IN ADVANCE!!!
BTW: A big thank you to all of you guys!! YOU ARE AMAZING! You can't believe how much impact VBA macros has in the company I work for (since I starting learning it and putting into practice, thanks to you)
Best regards, Roger
I have a code taking data of a one workbook (Workbook1) and putting the specified data into another workbook ("MasterFile" {Workbook2}). The code works fine if the MasterFile is NOT open, because the code works on the workbooks.open event.
What I would like is, when the MasterFile is ALREADY open, then populate a MsgBox saying something like "Workbook currently in use, please contact HR and try again later" AND exit the whole sub and return to the original data sheet (Workbook1). Please also note that the Workbook2 is password protected. I know this has probably been asked before, but I cannot find an answer corresponding to this specific issue.
Here is what I have now (not all of it, but the relevant code):
Private Sub CommandButton1_Click()
Dim MasterFile As Workbook
Set MasterFile = Workbooks.Open("G:\Time Tracking\FileName.xlsx", Password:="XY")
Worksheets("MasterFileHours").Select
Worksheets("MasterFileHours").Range("A1").Select
RowCount = Worksheets("MasterFileHours").Range("A1").CurrentRegion.Rows.Count
Application.ScreenUpdating = False
Application.Visible = False
With Worksheets("MasterFileHours").Range("A1")
.Offset(RowCount, 0).Value = WeekNo
.Offset(RowCount, 1).Value = xDate
.Offset(RowCount, 2).Value = EOWEEK
.Offset(RowCount, 3).Value = Employee
.Offset(RowCount, 4).Value = HoursEffective
.Offset(RowCount, 5).Value = HoursTarget
.Offset(RowCount, 6).Value = OverUnder
.Offset(RowCount, 7).Value = Pot60Increase
.Offset(RowCount, 8).Value = Pot60Decrease
End With
MasterFile.Save
MasterFile.Close
End Sub
THANKS IN ADVANCE!!!
BTW: A big thank you to all of you guys!! YOU ARE AMAZING! You can't believe how much impact VBA macros has in the company I work for (since I starting learning it and putting into practice, thanks to you)

Best regards, Roger