Hi,
I am trying to copy and pastespecial (values) a range of cells through VBA from one workbook to another. Here is my code thus far:
Both workbooks open fine and the open2007currentstore will copy the range perfectly. The problem exists in
where I keep getting a runtime "object required" error. I have tried a variety of alternatives activesheet.paste etc. but I am always arriving at the same error.
Any help would be greatly appreciated.
Happy Holidays!
I am trying to copy and pastespecial (values) a range of cells through VBA from one workbook to another. Here is my code thus far:
Code:
Private Sub copypastedata()
storeno = 20
While storeno <= 20
open2007currentstore = DLookup("location", "storelocation", "store=" & storeno)
open2008currentstore = DLookup("newlocation", "storelocation", "store=" & storeno)
Set xl4obj = CreateObject("Excel.application")
xl4obj.Workbooks.Open open2007currentstore
xl4obj.Application.Visible = True
xl4obj.Sheets("Sales Comparison").Activate
xl4obj.range("a1:i361").Select
xl4obj.Selection.Copy
'Set xl4obj = CreateObject("Excel.application")
Sleep (1000)
xl4obj.Workbooks.Open open2008currentstore
xl4obj.Application.Visible = True
xl4obj.Sheets("Sales Comparison").Activate
xl4obj.range("a1:i361").Select
Sleep (5000)
xl4obj.Selection.Pastespecial paste:=xlvalues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
xl4obj.Application.CutCopyMode = False
xl4obj.DisplayAlerts = False
xl4obj.Application.Quit
Set xl4obj = Nothing
Application.Quit
storeno = storeno + 10
Wend
End Sub
Both workbooks open fine and the open2007currentstore will copy the range perfectly. The problem exists in
Code:
xl4obj.Selection.Pastespecial paste:=xlvalues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Any help would be greatly appreciated.
Happy Holidays!