Hi All
I have some code that I am trying to use to copy the contents of a sheet in a workbook to another workbook. However , when the code is run I get "Runtime error 91: Object variable or With block variable" not set error. I have pasted my code below. Any ideas what is causing the error. Thanks in advance.
I have some code that I am trying to use to copy the contents of a sheet in a workbook to another workbook. However , when the code is run I get "Runtime error 91: Object variable or With block variable" not set error. I have pasted my code below. Any ideas what is causing the error. Thanks in advance.
VBA Code:
Sub Button1_Click()
Dim wb As Workbook
Dim wsDest As Worksheet
Dim wsSource As Worksheet
Dim srcValue As Range
Dim Dlg As FileDialog
Dim myFile As String
Set Dlg = Application.FileDialog(msoFileDialogFilePicker)
With Dlg
.Title = "Select the Dashboard"
.AllowMultiSelect = False
.Filters.Clear
If .Show = -1 Then
myFile = Dlg.SelectedItems(1)
Else
Exit Sub
End If
End With
Set wb = Workbooks.Open(myFile)
Set wsDest = ThisWorkbook.Worksheets("Learner List")
Set wsSource = wb.Worksheets("Learner List")
srcValue = Range(wsSource.Cells(4, 2), wsSource.Cells(11, 11))
Range(wsDest.Cells(4, 2), wsDest.Cells(11, 11)) = srcValue
ActiveWorkbook.Close SaveChanges:=True
End Sub