I hsve tried to write code to open a file in C:\Sales Reports by month" using a wilcard characterso to make it easier to select a file to open and copy the data for eg BR1 Sales Report Oct 2022.xlsm
I get a run time error 10 "This array is fixed or temorarily locked" and the code below is highlighted
See full code below
It would be appreciated if someone could amend my code
I get a run time error 10 "This array is fixed or temorarily locked" and the code below is highlighted
Code:
A = .SelectedItems(1)
See full code below
It would be appreciated if someone could amend my code
Code:
Sub Open_Workbook()
ChDir ("C:\Sales Reports by month")
A:
Dim A As Variant
Dim LR As Long
A = Application.GetOpenFilename(MultiSelect:=True)
If TypeName(A) = "Boolean" Then Exit Sub
Dim file As Variant
Application.ScreenUpdating = False
For Each file In A
With Workbooks.Open(file)
With Application.FileDialog(msoFileDialogFilePicker)
.ButtonName = "Open"
With .Filters
.Clear
.Add "Excel Files", "*.xlsm"
End With
.InitialFileName = "*BR1*.xlsm"
.Title = "Select File"
If .Show <> -1 Then Exit Sub
A = .SelectedItems(1)
End With
With Sheets(2)
.UsedRange.Copy _
Destination:=ThisWorkbook.Sheets("Imported Data").Range("A" & Rows.Count).End(xlUp).Offset(1)
End With
.Close SaveChanges:=False
End With
Next
Application.ScreenUpdating = True
End Sub