+ Reply to Thread
Results 1 to 2 of 2

ChangeLink with variable new name

Hybrid View

  1. #1
    Registered User
    Join Date
    09-03-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    ChangeLink with variable new name

    Hi,

    I set up a userform that lists the content of a folder in a combobox.
    I want to use the value selected by the user in the combobox as the name of the new file in a change link function.
    I am getting an error Method ChangeLink of object workbook failed.

    Here is the OK command in the form to trigger the ChangeLink:

    Sub OK_Click()
    
    
    Select Case BBList.Value
    Case "Select a BB"
    Unload SelectionList
    Exit Sub
    Case Else
    BBList.Value = BBVariant
    End Select
    
    Call ChangeLinks
    
    Unload SelectionList
    
    End Sub
    I had declared the BBVariant as public as follows:

    Public BBVariant As Long
    Here is the ChangeLinks sub

    Sub ChangeLinks()
    
        arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
       
        
          
        If Not IsEmpty(arrLinks) Then
            'On Error Resume Next
            Application.DisplayAlerts = False
            For i = LBound(arrLinks) To UBound(arrLinks)
                ActiveWorkbook.ChangeLink arrLinks(i), BBVariant, xlLinkTypeExcelLinks
            Next i
            Application.DisplayAlerts = True
            End If
        
    End Sub
    Of course, if I leave the on error resume next in, then I don't get the error message but the link is not updated.

    Many thanks for your help.

    Dee

  2. #2
    Registered User
    Join Date
    09-03-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: ChangeLink with variable new name

    I managed to get my code to work.

    Instead of using the variable BBVariant, I used the following in the ChangeLink :

        ActiveWorkbook.ChangeLink arrLinks(i), SelectionList.BBList.Value, xlLinkTypeExcelLinks
    Why could not I store the result of the combobox selection as a variable and re-use it in the ChangeLink formulae ?

    I would be SO grateful if somebody could explain this.

    Dee

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1