melodramatic
Board Regular
- Joined
- Apr 28, 2003
- Messages
- 187
- Office Version
- 365
- Platform
- Windows
I'm been tasked with creating a macro that will take a new listing of data, and compare it to existing data in my main workbook. Unfortunately, I keep getting hung up with it, and I am totally lost.
What I'm wanting to do -
Go to the specific folder, and choose the file to update (works fine)
Open that file and copy a range of data (works fine)
Go back to my original file (the one running the macro) - THIS IS WHERE I HANG UP - Run-time error '13'
Copy the data to a worksheet in my original file
Close the newly opened file (without saving)
Here's my coding...
I know it's something so simple that I should be slapped in the face, but I just can't figure it out. Help???
What I'm wanting to do -
Go to the specific folder, and choose the file to update (works fine)
Open that file and copy a range of data (works fine)
Go back to my original file (the one running the macro) - THIS IS WHERE I HANG UP - Run-time error '13'
Copy the data to a worksheet in my original file
Close the newly opened file (without saving)
Here's my coding...
Code:
Sub CompareData()
'
'
'
Dim WBPath As String
Dim WB1 As Workbook
'Dim WB2 As Workbook
Set WB1 = ActiveWorkbook
ChDrive "P:\"
ChDir "\ADMINISTRATIVE\Extension Macro\Updates"
WB2 = Application.GetOpenFilename
If OpenWB = "False" Then
Exit Sub
Else
Workbooks.Open Filename:=WB2
Range("A1:Z5000").Select
Selection.Copy
Workbooks(WB1).Activate ' THIS IS WHERE MY MACRO HANGS UP
Sheets("Compare").Select
Range("B5").Select
ActiveSheet.Paste
Workbooks(WB2).Activate
Workbooks(WB2).Close SaveChanges:=False
WB1.Activate
End If
End Sub
I know it's something so simple that I should be slapped in the face, but I just can't figure it out. Help???