brianfosterblack
Active Member
- Joined
- Nov 1, 2011
- Messages
- 251
I have 2 workbooks which are identical. Same layout, same named ranges and same macros. These are used by 2 staff members. Lets say staff member 1 uses workbook 1 and staff member 2 uses workbook 2
If staff member 1 gets a new client he adds a new sheet to his workbook for that client (New Client) and starts entering details about the client. After some time he decides the client must rather be served by staff member 2 so he wants to copy the worksheet over to workbook 2 of staff member 2.
This is the code I am using to transfer the workbook and remove any hyperlinks. Both workbooks are placed in the same directory to do this.
Code in the Module
Code in the userform
The worksheet transfers perfectly and everything seems fine at first.
The problem I am having is that when I then run a macro in Workbook 1 it seems to be linking to workbook 2 in some way. I am assuming this as the macro takes very long and sometimes freezes. Also if I close workbook 2 and open it again it tells me I have links to external sources. When I check the "Clear" menu item on Workbook 2, I see no hyperlinks. Can anyone help me with this and explain what is happening.
If staff member 1 gets a new client he adds a new sheet to his workbook for that client (New Client) and starts entering details about the client. After some time he decides the client must rather be served by staff member 2 so he wants to copy the worksheet over to workbook 2 of staff member 2.
This is the code I am using to transfer the workbook and remove any hyperlinks. Both workbooks are placed in the same directory to do this.
Code in the Module
VBA Code:
Public Sub CopySheetToEndAnotherWorkbook()
Load FrmCopySheet
FrmCopySheet.Show
If (FrmCopySheet.SelectedWorkbook <> "") Then
ActiveSheet.Copy After:=Workbooks( _
FrmCopySheet.SelectedWorkbook).Sheets( _
Workbooks(FrmCopySheet.SelectedWorkbook). _
Worksheets.Count)
End If
Unload FrmCopySheet
On Error Resume Next 'Trap error
For i = 1 To UBound(ar) 'Excel VBA loop throuh links
ActiveWorkbook.BreakLink ar(i), xlLinkTypeExcelLinks
Next i
On Error GoTo 0
End Sub
VBA Code:
Public SelectedWorkbook As String
Private Sub UserForm_Initialize()
SelectedWorkbook = ""
ListBox1.Clear
For Each wbk In Application.Workbooks
ListBox1.AddItem (wbk.Name)
Next
End Sub
Private Sub CommandButton1_Click()
If ListBox1.ListIndex > -1 Then
SelectedWorkbook = ListBox1.List(ListBox1.ListIndex)
End If
Me.Hide
End Sub
Private Sub CommandButton2_Click()
SelectedWorkbook = ""
Me.Hide
End Sub
The problem I am having is that when I then run a macro in Workbook 1 it seems to be linking to workbook 2 in some way. I am assuming this as the macro takes very long and sometimes freezes. Also if I close workbook 2 and open it again it tells me I have links to external sources. When I check the "Clear" menu item on Workbook 2, I see no hyperlinks. Can anyone help me with this and explain what is happening.