selecting several open worksheets

A

Annette

is there a way to select several open worksheets at a time??

I need to break the links on many worksheets - and do not want to do it
sheet by sheet by sheet by sheet, etc. is there a way to open several at a
time and get them all into the Edit Links window or is there another way to
accomplish the same thing?
 
J

Jim Thomlinson

Check out Bill Manville's FindLinks addin as an easy way to find and remove
all links in a workbook...
 
A

Annette

Thank you for the information - I downloaded the addin (and even found
another one I downloaded) - but maybe I just do not know what I am doing
because I can still only make changes one sheet at a time, even when I have 5
open. It only changes the active sheet - does anything change a whole book??
 
A

Annette

I really <miss-spoke in that last post. What I want to know is :

is there any way to change several (5) workbooks that are in the same
file/folder - each workbook only has one sheet and I need to change each
sheet in each file/folder (there are over 400 folders)
 
R

Ron de Bruin

Hi Annette

Test this for files in one folder
Change MyPath = "C:\Users\Ron\test"

If it is working I can change the sub for you so it is working also in every subfolder

Sub TestExample()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String, Fnum As Long
Dim mybook As Workbook
Dim CalcMode As Long
Dim sh As Worksheet
Dim ErrorYes As Boolean
Dim WorkbookLinks As Variant

'Fill in the path\folder where the files are
MyPath = "C:\Users\Ron\test"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
On Error GoTo 0

If Not mybook Is Nothing Then


'Break links in mybook
On Error Resume Next
With mybook
WorkbookLinks = .LinkSources(Type:=xlLinkTypeExcelLinks)
If IsArray(WorkbookLinks) Then
For i = LBound(WorkbookLinks) To UBound(WorkbookLinks)
.BreakLink _
Name:=WorkbookLinks(i), _
Type:=xlLinkTypeExcelLinks
Next i
Else
'No Links to other workbooks"
End If
End With


If Err.Number > 0 Then
ErrorYes = True
Err.Clear
'Close mybook without saving
mybook.Close savechanges:=False
Else
'Save and close mybook
mybook.Close savechanges:=True
End If
On Error GoTo 0
Else
'Not possible to open the workbook
ErrorYes = True
End If

Next Fnum
End If

If ErrorYes = True Then
MsgBox "There are problems in one or more files, possible problem:" _
& vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
End If

'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub
 
A

Annette

Ron -

WOW - you must be amazing!!! I know what you wrote is probably exactly what
I need, but I have no idea how to use it. Please give me some detales on
what I should do with all that great code!!!!!!!!

Joanne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top