I have the code below, but it throws up an Object Required error at the line: Set OpenBook = FileToOpen
Any ideas what I am doing wrong here?
Thanks for looking
VBA Code:
Sub Data()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Dim FileName As String
Application.WindowState = xlMaximized
Application.ScreenUpdating = False
ChDir Environ$("userprofile") & "\OneDrive\MJM Services\2.0 Quotations\xlsm Copy\"
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File", FileFilter:="Excel Files(*.xls*),*.xls*")
Workbooks.Open FileName:=FileToOpen
Set OpenBook = FileToOpen
If FileToOpen <> False Then
With OpenBook.Sheet1.Activate
.Range("A1:K500").Select
End With
Application.CutCopyMode = False
Selection.Copy
Workbooks("Quotations.xlsm").Sheets("Sheet1").Activate
Sheet5.Select
Cells.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Range("A1").Paste
Range("A1").Select
Application.CutCopyMode = False
Cells.Select
Cells.EntireColumn.AutoFit
OpenBook.Close False
Application.ScreenUpdating = True
End If
End Sub
Any ideas what I am doing wrong here?
Thanks for looking