PC Review


Reply
Thread Tools Rate Thread

Copy a selected Range to a Workbook

 
 
Dooley
Guest
Posts: n/a
 
      23rd Jun 2007
I am trying to copy a selected Range from the Main Database and Paste
it in a different Workbook,

I am using Excel 2007 but it doesn't seem to see the workbook that I
want to paste it to.

Here is the code.


Public Sub PrepareLabels()
Dim lrow As Range
Dim rc As Integer
Dim ar As Integer


Sheets(1).Activate

Set lrow = Sheet1.Range("A" & Rows.Count).End(xlUp)

lrow.Activate
ar = ActiveCell.row

Range(Cells(4, "a"), Cells(ar, "d")).Copy

Workbooks.Open Filename:="C:\Documents and Settings\Dennis\My Documents
\Excel\Labels.xls"
' Workbooks.Clear
' ActiveSheet.Delete
Range("A1").Select
ActiveSheet.Paste
Range("A2").Select
ActiveWorkbook.Save
End Sub


When the code gets to the line:- Workbooks.Open Filename:="C:
\Documents and Settings\Dennis\My Documents\Excel\Labels.xls" it
returns an error saying that the file can not be found. The filename
and everything is correct and the file does exist in the location
pointed to.

Can't seem to get around this.

Thankis for any suggestions.

Dooley

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Jun 2007
Open the file manually.

Then go into the vbe and create a macro that displays the full name of that
workbook:

msgbox thisworkbook.fullname
or
debug.print thisworkbook.fullname

And you'll see that there's a typo in your code (I betting!).

Dooley wrote:
>
> I am trying to copy a selected Range from the Main Database and Paste
> it in a different Workbook,
>
> I am using Excel 2007 but it doesn't seem to see the workbook that I
> want to paste it to.
>
> Here is the code.
>
> Public Sub PrepareLabels()
> Dim lrow As Range
> Dim rc As Integer
> Dim ar As Integer
>
> Sheets(1).Activate
>
> Set lrow = Sheet1.Range("A" & Rows.Count).End(xlUp)
>
> lrow.Activate
> ar = ActiveCell.row
>
> Range(Cells(4, "a"), Cells(ar, "d")).Copy
>
> Workbooks.Open Filename:="C:\Documents and Settings\Dennis\My Documents
> \Excel\Labels.xls"
> ' Workbooks.Clear
> ' ActiveSheet.Delete
> Range("A1").Select
> ActiveSheet.Paste
> Range("A2").Select
> ActiveWorkbook.Save
> End Sub
>
> When the code gets to the line:- Workbooks.Open Filename:="C:
> \Documents and Settings\Dennis\My Documents\Excel\Labels.xls" it
> returns an error saying that the file can not be found. The filename
> and everything is correct and the file does exist in the location
> pointed to.
>
> Can't seem to get around this.
>
> Thankis for any suggestions.
>
> Dooley


--

Dave Peterson
 
Reply With Quote
 
Dooley
Guest
Posts: n/a
 
      23rd Jun 2007
On Jun 23, 12:51 pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Open the file manually.
>
> Then go into the vbe and create a macro that displays the full name of that
> workbook:
>
> msgbox thisworkbook.fullname
> or
> debug.print thisworkbook.fullname
>
> And you'll see that there's a typo in your code (I betting!).
>

(Original snipped)

Thanks Dave. That was the answer. I had been using Excel97 and
upgraded to 2007 as I mentioned. 2007 needs the exact name of the
file and of course the file is no longer just xls but is now xlsx and
that was causing the error.

As usual I came to the right place for expert advice.

Thanks.

Dooley

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Jun 2007
Glad you found the difference.

Dooley wrote:
>
> On Jun 23, 12:51 pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> > Open the file manually.
> >
> > Then go into the vbe and create a macro that displays the full name of that
> > workbook:
> >
> > msgbox thisworkbook.fullname
> > or
> > debug.print thisworkbook.fullname
> >
> > And you'll see that there's a typo in your code (I betting!).
> >

> (Original snipped)
>
> Thanks Dave. That was the answer. I had been using Excel97 and
> upgraded to 2007 as I mentioned. 2007 needs the exact name of the
> file and of course the file is no longer just xls but is now xlsx and
> that was causing the error.
>
> As usual I came to the right place for expert advice.
>
> Thanks.
>
> Dooley


--

Dave Peterson
 
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
Copy Range from Open Workbook to Active Workbook Forgone Microsoft Excel Programming 0 17th Jul 2009 01:46 AM
Copying range from selected workbook to open workbook John Microsoft Excel Programming 2 11th Aug 2007 03:49 PM
Copy Range to a New WorkBook + Name Sheet a cell Value + Name WorkBook another Celll Value Corey Microsoft Excel Programming 2 2nd Nov 2006 05:01 AM
How do I edit a selected range then copy the range into an new sheet??? dwyborn Microsoft Excel Programming 2 16th Dec 2005 04:11 PM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Microsoft Excel Programming 3 24th Jun 2004 12:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:49 PM.