PC Review


Reply
Thread Tools Rate Thread

Copy / paste with VBA

 
 
Opal
Guest
Posts: n/a
 
      9th Feb 2009
I am trying to run the following from Access 2003:

Sub CopyPaste()

Dim lngColumn As Long
Dim xl As Object
Dim wb1 As Object
Dim wb2 As Object

Set xl = CreateObject("Excel.Application")

Set wb1 = xl.Workbooks("North Shop - Empl.xls")
Set wb2 = xl.Workbooks("temp.xls")

wb1.Range("A1:F471").Copy

wb2.Range("A1").Paste

End Sub

I am trying to perform a copy / paste between two excel
workbooks from my access database. I get a
"Subscript out of range" error and debugging points to:

Set wb1 = xl.Workbooks("North Shop - Empl.xls")

Can anyone help me get this working? Thank you.
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      9th Feb 2009
Hi,
try:
Set wb1 = xl.Workbooks.Open("North Shop - Empl.xls")

furthermore - I think should be a full path to North Shop - Empl.xls

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Opal" <(E-Mail Removed)> wrote in message
news:2235e9f4-88a5-442e-94c8-(E-Mail Removed)...
> I am trying to run the following from Access 2003:
>
> Sub CopyPaste()
>
> Dim lngColumn As Long
> Dim xl As Object
> Dim wb1 As Object
> Dim wb2 As Object
>
> Set xl = CreateObject("Excel.Application")
>
> Set wb1 = xl.Workbooks("North Shop - Empl.xls")
> Set wb2 = xl.Workbooks("temp.xls")
>
> wb1.Range("A1:F471").Copy
>
> wb2.Range("A1").Paste
>
> End Sub
>
> I am trying to perform a copy / paste between two excel
> workbooks from my access database. I get a
> "Subscript out of range" error and debugging points to:
>
> Set wb1 = xl.Workbooks("North Shop - Empl.xls")
>
> Can anyone help me get this working? Thank you.


 
Reply With Quote
 
Opal
Guest
Posts: n/a
 
      9th Feb 2009
On Feb 9, 1:19*pm, "Alex Dybenko"
<alex...@PLEASE.cemi.NO.rssi.SPAM.ru> wrote:
> Hi,
> try:
> Set wb1 = xl.Workbooks.Open("North Shop - Empl.xls")
>
> furthermore - I think should be a full path to North Shop - Empl.xls
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)http://accessblog.nethttp://www.PointLtd.com
>
> "Opal" <tmwel...@hotmail.com> wrote in message
>
> news:2235e9f4-88a5-442e-94c8-(E-Mail Removed)...
>
>
>
> > I am trying to run the following from Access 2003:

>
> > Sub CopyPaste()

>
> > Dim lngColumn As Long
> > Dim xl As Object
> > Dim wb1 As Object
> > Dim wb2 As Object

>
> > Set xl = CreateObject("Excel.Application")

>
> > Set wb1 = xl.Workbooks("North Shop - Empl.xls")
> > Set wb2 = xl.Workbooks("temp.xls")

>
> > wb1.Range("A1:F471").Copy

>
> > wb2.Range("A1").Paste

>
> > End Sub

>
> > I am trying to perform a copy / paste between two excel
> > workbooks from my access database. *I get a
> > "Subscript out of range" error and debugging points to:

>
> > Set wb1 = xl.Workbooks("North Shop - Empl.xls")

>
> > Can anyone help me get this working? *Thank you.- Hide quoted text -

>
> - Show quoted text -


Alex,

Thank you....actually, I found something else that works really well:

Sub OpenCopyPaste()
' open the source workbook and select the source sheet
Workbooks.Open Filename:="L:\HR\Confidential\North Shop Empl data.xls"
Sheets("Sheet1").Select
' copy the source range
Sheets("Sheet1").Range("A1:F550").Select
Selection.Copy

' select current workbook and paste the values starting at A1
Windows("Empl Data(temp).xls").Activate
Sheets("Sheet1").Select
Sheets("Sheet1").Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Save
End Sub
 
Reply With Quote
 
AlexM
Guest
Posts: n/a
 
      10th Feb 2009
Bingo

"Opal" wrote:

> On Feb 9, 1:19 pm, "Alex Dybenko"
> <alex...@PLEASE.cemi.NO.rssi.SPAM.ru> wrote:
> > Hi,
> > try:
> > Set wb1 = xl.Workbooks.Open("North Shop - Empl.xls")
> >
> > furthermore - I think should be a full path to North Shop - Empl.xls
> >
> > --
> > Best regards,
> > ___________
> > Alex Dybenko (MVP)http://accessblog.nethttp://www.PointLtd.com
> >
> > "Opal" <tmwel...@hotmail.com> wrote in message
> >
> > news:2235e9f4-88a5-442e-94c8-(E-Mail Removed)...
> >
> >
> >
> > > I am trying to run the following from Access 2003:

> >
> > > Sub CopyPaste()

> >
> > > Dim lngColumn As Long
> > > Dim xl As Object
> > > Dim wb1 As Object
> > > Dim wb2 As Object

> >
> > > Set xl = CreateObject("Excel.Application")

> >
> > > Set wb1 = xl.Workbooks("North Shop - Empl.xls")
> > > Set wb2 = xl.Workbooks("temp.xls")

> >
> > > wb1.Range("A1:F471").Copy

> >
> > > wb2.Range("A1").Paste

> >
> > > End Sub

> >
> > > I am trying to perform a copy / paste between two excel
> > > workbooks from my access database. I get a
> > > "Subscript out of range" error and debugging points to:

> >
> > > Set wb1 = xl.Workbooks("North Shop - Empl.xls")

> >
> > > Can anyone help me get this working? Thank you.- Hide quoted text -

> >
> > - Show quoted text -

>
> Alex,
>
> Thank you....actually, I found something else that works really well:
>
> Sub OpenCopyPaste()
> ' open the source workbook and select the source sheet
> Workbooks.Open Filename:="L:\HR\Confidential\North Shop Empl data.xls"
> Sheets("Sheet1").Select
> ' copy the source range
> Sheets("Sheet1").Range("A1:F550").Select
> Selection.Copy
>
> ' select current workbook and paste the values starting at A1
> Windows("Empl Data(temp).xls").Activate
> Sheets("Sheet1").Select
> Sheets("Sheet1").Range("A1").Select
> ActiveSheet.Paste
> Application.CutCopyMode = False
> ActiveWorkbook.Save
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get copy/paste to copy/paste text and not the whole page =?Utf-8?B?Q2Fyb2wgSi4=?= Microsoft Word Document Management 1 6th May 2005 09:03 PM
Copy and Paste macro needs to paste to a changing cell reference =?Utf-8?B?bG91bG91?= Microsoft Excel Programming 0 24th Feb 2005 10:29 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel New Users 0 10th Mar 2004 07:06 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel Misc 0 10th Mar 2004 07:06 AM
Re: Copy/Paste in Excel prints highlighted cells and does not paste Dave Peterson Microsoft Excel Misc 0 30th Jul 2003 11:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 AM.