I am trying to:
1. open all linked workbooks (if not already open)
2. Copy some formulae that use the links, calculate the copied formulae then convert them to values.
3. Close the workbooks that I opened.
This is a generic, frequently used routine rather than limited to a particular project. Currently I do steps 1 and 3 manually.
The code I have so far for steps 1 and 3 is below.
Issue of the moment:
I can't perform step 3.
Workbooks(arLinks(intIndex)).Close SaveChanges:=False
Gives "Subscript out of range"
Other Unresolved Issues:
1a I have not managed to identify if the workbook is already open
1b If the workbook that is opened itself has links then I want to tell it not to update the links
1c I would be better searching the formulae I am about to copy (Selection.offset(-2,0)) for links that are referred to in them rather than open all linked workbooks. I'll look at that later.
I am workin in xl 2003 at the moment but needs to run on xl 2000.
I would appreciate any pointers!
Regards,
Gavin
1. open all linked workbooks (if not already open)
2. Copy some formulae that use the links, calculate the copied formulae then convert them to values.
3. Close the workbooks that I opened.
This is a generic, frequently used routine rather than limited to a particular project. Currently I do steps 1 and 3 manually.
The code I have so far for steps 1 and 3 is below.
Issue of the moment:
I can't perform step 3.
Workbooks(arLinks(intIndex)).Close SaveChanges:=False
Gives "Subscript out of range"
Other Unresolved Issues:
1a I have not managed to identify if the workbook is already open
1b If the workbook that is opened itself has links then I want to tell it not to update the links
1c I would be better searching the formulae I am about to copy (Selection.offset(-2,0)) for links that are referred to in them rather than open all linked workbooks. I'll look at that later.
Code:
Sub OpenAllLinks()
Dim arLinks As Variant
Dim intIndex As Integer
Dim MyWb As Workbook
Set MyWb = ActiveWorkbook
arLinks = MyWb.LinkSources(xlExcelLinks)
If Not IsEmpty(arLinks) Then
For intIndex = LBound(arLinks) To UBound(arLinks)
MsgBox "Opening linked file" & arLinks(intIndex)
MyWb.OpenLinks arLinks(intIndex)
Next intIndex
Else
MsgBox "The active workbook contains no external links."
End If
End Sub
Sub CloseAllLinks()
Dim arLinks As Variant
Dim intIndex As Integer
Dim MyWb As Workbook
Set MyWb = ActiveWorkbook
arLinks = MyWb.LinkSources(xlExcelLinks)
If Not IsEmpty(arLinks) Then
For intIndex = LBound(arLinks) To UBound(arLinks)
MsgBox "Closing linked file" & arLinks(intIndex)
Workbooks(arLinks(intIndex)).Close SaveChanges:=False
Next intIndex
Else
MsgBox "The active workbook contains no external links."
End If
End Sub
I am workin in xl 2003 at the moment but needs to run on xl 2000.
I would appreciate any pointers!
Regards,
Gavin