I've done a summary workbook of some workbooks located in some different drives which I want to update (as they rely on INDIRECT in my workbook) by simply opening the files, and in extension update all values (hopefully). What I've tried is to implement a CommandButton through Developer tab and ActiveX Controls. I then right click this button and "View code" where I simply got "Private Sub CommandButton21_Click" and "End Sub" which I gather means that the "button's name" is CommandButton21.
My code looks like this:
Private Sub CommandButton21_Click()
Dim WbookCheck As Workbook
Dim sPath As String, sFile As String
On Error Resume Next
sPath = "C:\Pathtofile"
sFile = sPath & "filename.xlsx"
Set WbookCheck = Workbooks(sFile)
On Error GoTo 0
If CommandButton21.Value = True Then
If WbookCheck Is Nothing Then 'Closed
Workbooks.Open Filename:=sFile, ReadOnly:=True
ElseIf Application.ActiveWorkbook.Name = WbookCheck.Name Then
WbookCheck.Close SaveChanges:=True
Else
WbookCheck.Activate
End If
Else
WbookCheck.Close True
End If
End Sub
Does anybody have a clue regarding this?
sPath = "C:\Pathtofile\`Does that help?