Hello, please could you advise how to connect checkboxes with VBA to adjust excel files.
I have excel files for 11 entities (countries).
I need to do adjustment sometimes on each of them or sometimes only chose which file should be adjusted.
I created checkboxes with labels:
I need Access VBA for open, save and close related excel files. The issue is that it always opens, saves and closes only file for first country and then states "debug".
Files names are the same as label captions connected with checkbox and ".xls" at the end.
Here is what I tried:
Thanks for your advice in advance.
I have excel files for 11 entities (countries).
I need to do adjustment sometimes on each of them or sometimes only chose which file should be adjusted.
I created checkboxes with labels:
Code:
x Select All x country1 x country2 ...... ...... x country11
Files names are the same as label captions connected with checkbox and ".xls" at the end.
Here is what I tried:
Code:
Dim LoopIndex As Integer
Set xlapp = CreateObject("Excel.Application")
xlapp.DisplayAlerts = False
filepath = "path to the file"
For LoopIndex = 1 To 11
Select Case Me.Controls("CB" & LoopIndex)
Case Me.Controls("CB" & LoopIndex) = True
xlapp.workbooks.Open filepath & Me.Controls("LB" & LoopIndex).Caption & ".xls"
xlapp.Visible = True
xlapp.ActiveWorkbook.Save
xlapp.ActiveWorkbook.Close
Set xlapp = Nothing
End Select
Next LoopIndex
Comment