Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy a selected Range to a Workbook

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy a selected Range to a Workbook

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy a selected Range to a Workbook

On Jun 23, 12:51 pm, Dave Peterson 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy a selected Range to a Workbook

Glad you found the difference.

Dooley wrote:

On Jun 23, 12:51 pm, Dave Peterson 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make copy of workbook based on selected criteria Anthony[_5_] Excel Worksheet Functions 3 March 30th 10 10:57 PM
How do I edit a selected range then copy the range into an new sheet??? dwyborn Excel Programming 2 December 16th 05 04:11 PM
copy selected cells to new workbook? Chimanrao Excel Programming 6 October 23rd 05 06:33 PM
Nameing a range while still selected from copy Jim at Eagle Excel Programming 5 April 10th 05 07:21 PM
Copy selected data to new workbook Pete[_8_] Excel Programming 3 July 19th 03 01:24 AM


All times are GMT +1. The time now is 02:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"