Another Macro and linking question

kluitna

Board Regular
Joined
Mar 10, 2002
Messages
75
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.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top