Error pasting worksheets using Access VBA

Pikeboy

Registered User.
Local time
Yesterday, 21:42
Joined
May 24, 2012
Messages
11
When trying to run the below code in Access I get the following Run-time '1004' error:

"To paste all cells from an Excel worksheet into the current worksheet, you must paste into the first cell (A1 or R1C1)."

Set wkBkObj = Workbooks.Open("Somewhere" & strName)
Set wkBkName = Workbooks.Open("Somewhere\FileName.xlsx")

Set xlSheet = wkBkObj.Worksheets(1)
xlSheet.Cells.Copy

wkBkName.Worksheets(1).Paste <-------- Code hangs up here
xlSheet.Cells(1, 1).Copy
wkBkObj.Close
wkBkName.Save
wkBkName.Close
Set wkBkObj = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing


Any ideas? Thanks in advance.
 
Try the following code change, from:
Code:
xlSheet.Cells.Copy

wkBkName.Worksheets(1).Paste
...to:
Code:
xlSheet.UsedRange.Copy

wkBkName.Worksheets(1).Paste
Application.CutCopyMode = [COLOR="Navy"]False[/COLOR]
 
Does not seem to like the last line you gave me. States "Method or data member not found"

Not sure if I've clarified well but this code is taking place in Access. Does the version matter?
 
My mistake, that line should read:
Code:
wkBkObj.Application.CutCopyMode = [COLOR="Navy"]False[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom