Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Trapping Erros on ChangeLinks

I have written this code which changes the links on a workbook in a preset
drive\filepath\location to the workbook which initiated the
"ResetBaseLedgerLinksToCurrentWorkbook" macro. The purpose of the error
trapping is to prevent the end user from resetting the link to the workbook
to which the link already exists. If the link already exists it seems to be
removing the link information. There is only one link source for the file
although there are thousands of cells linked between the two workbooks -
there is only one source at a time.

For example: if the link is to workbook "XYZ" and that is the current link,
it seems to remove that link, not replace it. What I ended up with is a huge
mass of circular references.

So I wrote the below. I'm not sure if I covered all my bases. Any
suggestions would be appreciated on how to trap for all of the potential
errors.

Option Explicit
Sub ResetBaseLedgerLinksToCurrentWorkbook()
' Reset the PFUL2005Ledger Links To Current Workbook
Dim varNewLinkName As Variant
Dim varOldLinkName As Variant
Dim varOldLinks As Variant
Dim wbConceptWorkbook As Workbook
Dim wbComplianceWorkbook As Workbook
Set wbConceptWorkbook = ThisWorkbook
wbConceptWorkbook.Activate
Worksheets("Inputs").Calculate
varNewLinkName = Worksheets("Inputs").Range("A90").Value
Set wbComplianceWorkbook = Workbooks("PFUL2005Ledger.xls")
varOldLinks = wbComplianceWorkbook.LinkSources
varOldLinkName = varOldLinks(1)
If varOldLinkName = varNewLinkName Then
GoTo NoChange
Else
On Error GoTo ErrorOnChange
wbComplianceWorkbook.ChangeLink Name:=varOldLinkName, NewName:= _
varNewLinkName, Type:=xlExcelLinks
wbConceptWorkbook.Activate
wbConceptWorkbook.Worksheets("Inputs").Range("A89" ).Select
Worksheets("Inputs").Calculate
wbConceptWorkbook.Worksheets("Inputs").Range("A1") .Select
End If
NoChange:
Set wbComplianceWorkbook = Nothing
Set wbConceptWorkbook = Nothing
Exit Sub
ErrorOnChange:
MsgBox "Error in changing links"
GoTo NoChange
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Trapping Erros on ChangeLinks ADDITIONAL INFORMATION

The real problem is, I believe, is that it will start changing the links,
get to a point where it runs into an error which triggers the OnError. Is
there a way to tell it to revert to return to its original state before the
replacement process started? One solutioon would be to simply not save the
file. Perhaps I should have the OnError close the file without saving and
then reopen it.

The number of linked cells is about 15,120.

Previously I had the end users doing this changelink manually. Perhaps they
should revert to that as they are a small group and are generally fairly
experienced end users.

"qwerty" wrote in message
...
I have written this code which changes the links on a workbook in a preset
drive\filepath\location to the workbook which initiated the
"ResetBaseLedgerLinksToCurrentWorkbook" macro. The purpose of the error
trapping is to prevent the end user from resetting the link to the workbook
to which the link already exists. If the link already exists it seems to be
removing the link information. There is only one link source for the file
although there are thousands of cells linked between the two workbooks -
there is only one source at a time.

For example: if the link is to workbook "XYZ" and that is the current
link, it seems to remove that link, not replace it. What I ended up with
is a huge mass of circular references.

So I wrote the below. I'm not sure if I covered all my bases. Any
suggestions would be appreciated on how to trap for all of the potential
errors.

Option Explicit
Sub ResetBaseLedgerLinksToCurrentWorkbook()
' Reset the PFUL2005Ledger Links To Current Workbook
Dim varNewLinkName As Variant
Dim varOldLinkName As Variant
Dim varOldLinks As Variant
Dim wbConceptWorkbook As Workbook
Dim wbComplianceWorkbook As Workbook
Set wbConceptWorkbook = ThisWorkbook
wbConceptWorkbook.Activate
Worksheets("Inputs").Calculate
varNewLinkName = Worksheets("Inputs").Range("A90").Value
Set wbComplianceWorkbook = Workbooks("PFUL2005Ledger.xls")
varOldLinks = wbComplianceWorkbook.LinkSources
varOldLinkName = varOldLinks(1)
If varOldLinkName = varNewLinkName Then
GoTo NoChange
Else
On Error GoTo ErrorOnChange
wbComplianceWorkbook.ChangeLink Name:=varOldLinkName, NewName:= _
varNewLinkName, Type:=xlExcelLinks
wbConceptWorkbook.Activate
wbConceptWorkbook.Worksheets("Inputs").Range("A89" ).Select
Worksheets("Inputs").Calculate
wbConceptWorkbook.Worksheets("Inputs").Range("A1") .Select
End If
NoChange:
Set wbComplianceWorkbook = Nothing
Set wbConceptWorkbook = Nothing
Exit Sub
ErrorOnChange:
MsgBox "Error in changing links"
GoTo NoChange
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup Erros KMJ Excel Discussion (Misc queries) 2 November 5th 09 12:11 AM
Erros when saving workbook with different name GeorgeA Excel Discussion (Misc queries) 0 July 30th 09 03:35 PM
VLOOKUP - Referencing seperate workbook getting #N/A erros Reddo Excel Worksheet Functions 2 December 3rd 08 07:42 PM
Formula erros =#N/A Tia[_3_] Excel Worksheet Functions 2 June 4th 08 04:25 PM
error trapping [email protected] Excel Programming 2 April 5th 05 12:52 AM


All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"