CantGetRight
New Member
- Joined
- Jul 21, 2015
- Messages
- 21
Hi there,
I have a macro which opens files based on the contents of a cell range. This cell range has the file names and the macro specifies the folder directory. The macro opens whatever cells are selected and then it closes all files.
I want it to run as is but with one minor tweak - only to close the files it opened (selected cells) and to leave the other Excel files open.
Can anyone help?
Thanks - Code Below.
Mark
Sub OpenWorkBooksandRefreshFormulas()
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'safety prompt
Dim Sure As Integer
Sure = MsgBox("This is a sample message box.", vbYesNo)
If Sure = vbYes Then
Set MasterWB = ThisWorkbook
Dim filename As String
On Error Resume Next
For Each r In Selection
Workbooks.Open filename:= _
"\\Sample File Path\2015\" & r.Value & ".xlsm", UpdateLinks:=0
Next
MasterWB.Activate
On Error Resume Next
Calculate
On Error Resume Next
Dim xWB As Workbook
On Error Resume Next
For Each xWB In Application.Workbooks
If Not (xWB Is Application.ActiveWorkbook) Then
xWB.Close savechanges:=False
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
End Sub
I have a macro which opens files based on the contents of a cell range. This cell range has the file names and the macro specifies the folder directory. The macro opens whatever cells are selected and then it closes all files.
I want it to run as is but with one minor tweak - only to close the files it opened (selected cells) and to leave the other Excel files open.
Can anyone help?
Thanks - Code Below.
Mark
Sub OpenWorkBooksandRefreshFormulas()
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'safety prompt
Dim Sure As Integer
Sure = MsgBox("This is a sample message box.", vbYesNo)
If Sure = vbYes Then
Set MasterWB = ThisWorkbook
Dim filename As String
On Error Resume Next
For Each r In Selection
Workbooks.Open filename:= _
"\\Sample File Path\2015\" & r.Value & ".xlsm", UpdateLinks:=0
Next
MasterWB.Activate
On Error Resume Next
Calculate
On Error Resume Next
Dim xWB As Workbook
On Error Resume Next
For Each xWB In Application.Workbooks
If Not (xWB Is Application.ActiveWorkbook) Then
xWB.Close savechanges:=False
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
End Sub