Another Macro and linking question
VBA Telemetry pings you when your VBA projects fail
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Another Macro and linking question

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    75
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Thanks to all who have helped me so far. I have 2 quick questions.

    I have the current code as follows:
    Sub test()
    Dim Source As String
    Dim Path As String
    Dim sht As String
    Path = Worksheets("List").Cells(1, 1)
    For i = 0 To 500
    Source = Worksheets("list").Cells(2 + i, 1)
    ChDir Path
    Workbooks.Open FileName:=Source
    Windows("Estimate Summary.xls").Activate
    Worksheets("ITEMS").Select
    Worksheets("ITEMS").Cells(6 + i, 1).Select
    strfile = Source
    ActiveCell.FormulaR1C1 = "='" & strfile & "'!R9C3"
    If Source = blank Then End
    Next
    End Sub
    And it works fine, what I can't figure out is how to get the a variable for every given worksheeet in the workbook soucre. As you can tell Souce just refereces a cell in the current worksheet that is a name of a workbook with souce information. Each souce workworrk has 30 worksheets in it. The above works great in getting to the first worksheet. Then it stops. Any sugestions out there?

    Also is there a way to go into workbooks and disassociate all the old links? I have kind of made a mess of some sheets experimenting with these macros linking them together. When I am done I don't want a bunch of bogus links lurking out there.

    Thanks in advance, this forum is a great resouce.

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I haven't tested this code, but it should work:
    Sub test()
    Dim Source As String
    Dim Path As String
    Dim NumSheets As Long
    Dim SheetName As String
    NumSheets = ThisWorkbook.Worksheets.Count
    For h = 1 To NumSheets
    SheetName = ThisWorkbook.Worksheets(h).Name
    Path = Worksheets(SheetName).Cells(1, 1)
    For i = 0 To 500
    Source = Worksheets(SheetName).Cells(2 + i, 1)
    ChDir Path
    Workbooks.Open Filename:=Source
    Windows("Estimate Summary.xls").Activate
    Worksheets(SheetName).Select
    Worksheets(SheetName).Cells(6 + i, 1).Select
    strfile = Source
    ActiveCell.FormulaR1C1 = "='" & strfile & "'!R9C3"
    If Source = blank Then End
    Next
    Next h
    End Sub

    Hope this helps.
    Kind regards, Al.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com