Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Paste Values

I'm writing a report building application in MS Access, at one point in the
program, it's supposed to open two seperate Excel workbooks, and copy data in
selected cells from one workbook to the other. The particular function that
I've written and am having trouble with is included below. Keep in mind that
SourceBook and TargetBook are declared with module scope, and by the time
this function is called the workbooks are already open, and it has been
proven that the program does have access to them correctly.

The problem is occuring where I'm pasting the data into the targetbook. The
error I'm getting is # 1004: PasteSpecial method of Worksheet class failed.
What am I doing wrong here? I've apparently gone code blind and can't see
the obvious.

Private Sub DoReportCopy(ByVal CellRange As String, ByVal PasteCell As String)
On Error GoTo errDoReportCopy
' Select CellRange from source book
SourceBook.Application.Range(CellRange).Select
' Copy selection
SourceBook.Application.Selection.Copy
' Select CellRange in target book
TargetBook.Application.Range(PasteCell).Select
' Paste values
TargetBook.Application.ActiveSheet.PasteSpecial Format:=3, Link:=1,
DisplayAsIcon:=False, IconFileName:=False
Exit Sub
errDoReportCopy:
Log.WriteLog "Error copying data in cell range " & CellRange & " to " &
PasteCell & ".", "SummaryReport.DoReportCopy", Err
End Sub

--
"Why live in the real world adhering to thier rules, when you can live in
code and write your own"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Paste Values

Nevermind. I figured it out. I had to change the function to the following

Private Sub DoReportCopy(ByVal CellRange As String, ByVal PasteCell As String)
On Error GoTo errDoReportCopy
' Select CellRange from source book
SourceBook.Application.Range(CellRange).Copy
' Select CellRange in target book
TargetBook.Application.Range(PasteCell).PasteSpeci al xlPasteValues
Exit Sub
errDoReportCopy:
Log.WriteLog "Error copying data in cell range " & CellRange & " to " &
PasteCell & ".", "SummaryReport.DoReportCopy", Err
End Sub

--
"Why live in the real world adhering to thier rules, when you can live in
code and write your own"


"Magius96" wrote:

I'm writing a report building application in MS Access, at one point in the
program, it's supposed to open two seperate Excel workbooks, and copy data in
selected cells from one workbook to the other. The particular function that
I've written and am having trouble with is included below. Keep in mind that
SourceBook and TargetBook are declared with module scope, and by the time
this function is called the workbooks are already open, and it has been
proven that the program does have access to them correctly.

The problem is occuring where I'm pasting the data into the targetbook. The
error I'm getting is # 1004: PasteSpecial method of Worksheet class failed.
What am I doing wrong here? I've apparently gone code blind and can't see
the obvious.

Private Sub DoReportCopy(ByVal CellRange As String, ByVal PasteCell As String)
On Error GoTo errDoReportCopy
' Select CellRange from source book
SourceBook.Application.Range(CellRange).Select
' Copy selection
SourceBook.Application.Selection.Copy
' Select CellRange in target book
TargetBook.Application.Range(PasteCell).Select
' Paste values
TargetBook.Application.ActiveSheet.PasteSpecial Format:=3, Link:=1,
DisplayAsIcon:=False, IconFileName:=False
Exit Sub
errDoReportCopy:
Log.WriteLog "Error copying data in cell range " & CellRange & " to " &
PasteCell & ".", "SummaryReport.DoReportCopy", Err
End Sub

--
"Why live in the real world adhering to thier rules, when you can live in
code and write your own"

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
Change paste to only paste values Chris Trygstad Excel Programming 1 November 6th 08 08:07 PM
find values in multiple cells and paste row values izzyt1972 Excel Discussion (Misc queries) 5 December 26th 07 10:14 PM
can you change the default paste method? (paste values) David A Brown Excel Discussion (Misc queries) 3 December 18th 07 09:59 AM
Dynamic Copy/Paste Special Formulas/Paste Special Values Sharon Perez Excel Programming 3 August 7th 04 09:49 PM
How do i compare values from two sheet and copy & paste if values match? rozb Excel Programming 0 March 5th 04 12:06 AM


All times are GMT +1. The time now is 10:21 PM.

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

About Us

"It's about Microsoft Excel"