Results 1 to 6 of 6

Thread: Linking Cells in Excel

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Linking Cells in Excel

    I wan to link cells in my Source.xls into my Recieving.xls workbook. I kow you can do this by the following (without code, i.e in Excel)

    Open both workbooks.
    Select the range on the "sending" worksheet.
    edit|copy
    select the range on the "receiving" worksheet that should be linked.
    edit|Paste special|paste link

    But can this be done withing VBA, VB or VB.Net?

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Linking Cells in Excel

    Some assumptions:
    Sheet that will contain the link = "NewSheet"
    Cell that will contain the link = "D2"
    Workbook that contains source info = "LinkedBook.xls"
    Sheet in above workbook that you are linking to = "LinkedSheet"
    Cell that will contain the source info = "A1"

    VB Code:
    1. Sheets("NewSheet").Range("$D$2").Formula = "='[LinkedBook.xls]LinkedSheet'!$A$1"

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Linking Cells in Excel

    mikeyc - You will also need the full path to the source workbook

    VB Code:
    1. Sub CreateLink()
    2. Dim sSourcePath As String
    3. Dim sSourceBook As String
    4. Dim sSourceSheet As String
    5. Dim sSourceRange As String
    6. Dim sFullAddress As String
    7.  
    8.     sSourcePath = "C:\Files\" 'Put the complete path to you source workbook here
    9.     sSourceBook = "YourSourceWorkbook.xls" 'put the name of your source workbook here
    10.     sSourceSheet = "YourSheetname" 'put the name of your sdource worksheet here
    11.     sSourceRange = "B12" 'put the address of the source cell here
    12.        
    13.     sFullAddress = "='" & sSourcePath
    14.     sFullAddress = sFullAddress & "[" & sSourceBook & "]"
    15.     sFullAddress = sFullAddress & sSourceSheet & "'!"
    16.     sFullAddress = sFullAddress & sSourceRange
    17.    
    18.     Range("C1").Formula = sFullAddress 'Put the cell where you want the link here
    19. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Linking Cells in Excel

    Although you don't need the full path if the workbook you're looking for is in the same folder or a subfolder of the folder from which you're running the spreadsheet.

    zaza

  5. #5

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Linking Cells in Excel

    So if I have a bunch of Spreadsheets in the same folder named EXCELLINKS I dont need the full path just the workbook name?

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  6. #6
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Linking Cells in Excel

    Try it!

Posting Permissions

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



Click Here to Expand Forum to Full Width