Try this out, make sure the WorkBook is in a folder that matches the code.
OriginalWorkBook is the workbook that has the data to send to the GetNewData workbook.
I have tested it many times and have not received an error.
Sub SendNewData()
Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet, ws2 As Worksheet, rng1 As Range, rng2 As Range, rng3 As Range, rng4 As Range
Set wb1 = Workbooks("GetNewData.xls")
Set wb2 = Workbooks("OriginalWorkBook.xls")
Set ws1 = wb1.Worksheets("Sheet1")
Set ws2 = wb2.Worksheets("Sheet1")
Set rng1 = ws1.Range("A65536").End(xlUp).Offset(1, 0)
Set rng2 = ws1.Range("B65536").End(xlUp).Offset(1, 0)
Set rng3 = ws1.Range("C65536").End(xlUp).Offset(1, 0)
Set rng4 = ws1.Range("D65536").End(xlUp).Offset(1, 0)
Application.DisplayAlerts = False
rng1 = ws2.Range("E13")
rng2 = ws2.Range("B7")
rng3 = ws2.Range("D19")
rng4 = ws2.Range("B2")
End Sub
Sub OpenBook()
Dim wb1 As Workbook
On Error Resume Next
Set wb1 = Workbooks("GetNewData.xls")
If wb1 Is Nothing Then 'Not open
Workbooks.Open Filename:="C:\Excel\GetNewData.xls" ' change this to your folder
SendNewData
ActiveWorkbook.Close savechanges:=True
On Error GoTo 0
Else: 'is open
With wb1
SendNewData
.Close savechanges:=True
End With
End If
End Sub
Bookmarks