I'm having major issues and no one in my office seems to be able to help. I've searched this site as well as google extensivly and have found no answers.
I have two worksheets (sheets 1&3) within one workbook, each worksheet is linked to a different file. Normally I'd go to "edit links" and update the source manually for both worksheets, this is no longer a viable solution and needs to be automated. Both worksheets are protected with the same password.
I've got it so it'll unlock both worksheets, however instead of only updating the worksheet i've selected it updates both worksheets with the same information.
I'm exteremly green when it comes to VBA so any help will need to be dumbed down, the following has been pieced together from the internet and a programmer here who quite frankly hasnt been all that helpful.
This is exteremely time sensitive so any help or insight would be greatly appreciated. I'm stuck.
Thanks.
Sub MyChangeLinkSource()
Dim varFileName As Variant
Dim arrLinks As Variant
Dim ws As Worksheet
Dim msg As String
Dim I As Long
'Object references
Set ws = ActiveSheet
'Check for links
arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
If IsEmpty(arrLinks) Then
msg = "This workbook does not contain any links!"
MsgBox msg
Exit Sub
End If
'Unprotect worksheet
For I = 1 To Sheets.Count
If I = 1 Or I = 3 Then
Sheets(I).Select
ActiveSheet.Unprotect Password:="HEYNOW123"
End If
Next I
'Get new source file
varFileName = Application.GetOpenFilename(Title:="Select a File to Import")
On Error Resume Next
If varFileName = "False" Then End
On Error GoTo 0
'Error handler to re-protect workbook in case of errors
On Error GoTo Handler
'Change link source
arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
ActiveWorkbook.ChangeLink arrLinks(1), varFileName, xlExcelLinks
'Re-protect and exit sub
MyExitSub:
For I = 1 To Sheets.Count
If I = 1 Or I = 3 Then
Sheets(I).Select
ActiveSheet.Protect Password:="HEYNOW123"
End If
Next I
Exit Sub
'Handle errors
Handler:
msg = "Error " & Err.Number & vbCrLf & Err.Description
msg = msg & vbCrLf & vbCrLf & "Please see Todd Devrieze for assistance."
MsgBox msg
Resume MyExitSub
End Sub
I have two worksheets (sheets 1&3) within one workbook, each worksheet is linked to a different file. Normally I'd go to "edit links" and update the source manually for both worksheets, this is no longer a viable solution and needs to be automated. Both worksheets are protected with the same password.
I've got it so it'll unlock both worksheets, however instead of only updating the worksheet i've selected it updates both worksheets with the same information.
I'm exteremly green when it comes to VBA so any help will need to be dumbed down, the following has been pieced together from the internet and a programmer here who quite frankly hasnt been all that helpful.
This is exteremely time sensitive so any help or insight would be greatly appreciated. I'm stuck.
Thanks.
Sub MyChangeLinkSource()
Dim varFileName As Variant
Dim arrLinks As Variant
Dim ws As Worksheet
Dim msg As String
Dim I As Long
'Object references
Set ws = ActiveSheet
'Check for links
arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
If IsEmpty(arrLinks) Then
msg = "This workbook does not contain any links!"
MsgBox msg
Exit Sub
End If
'Unprotect worksheet
For I = 1 To Sheets.Count
If I = 1 Or I = 3 Then
Sheets(I).Select
ActiveSheet.Unprotect Password:="HEYNOW123"
End If
Next I
'Get new source file
varFileName = Application.GetOpenFilename(Title:="Select a File to Import")
On Error Resume Next
If varFileName = "False" Then End
On Error GoTo 0
'Error handler to re-protect workbook in case of errors
On Error GoTo Handler
'Change link source
arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
ActiveWorkbook.ChangeLink arrLinks(1), varFileName, xlExcelLinks
'Re-protect and exit sub
MyExitSub:
For I = 1 To Sheets.Count
If I = 1 Or I = 3 Then
Sheets(I).Select
ActiveSheet.Protect Password:="HEYNOW123"
End If
Next I
Exit Sub
'Handle errors
Handler:
msg = "Error " & Err.Number & vbCrLf & Err.Description
msg = msg & vbCrLf & vbCrLf & "Please see Todd Devrieze for assistance."
MsgBox msg
Resume MyExitSub
End Sub