Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I copy and paste ranges from VB 6.0 in an Excel spreadsheet?

I have a VB program that is trying to edit an Excel spreadsheet.

It fails on the last line I listed in my code below, which is the paste.
The error I get is:
Method 'PasteSpecial' of object 'Range' failed

Dim ogn As Excel.Range
Dim filenam As String
Dim ex As Excel.Workbook
Dim sheetnam As String
dim ogn as Excel.range
dim Ognto as Excel.range

filenam = File1.Path & "\" & File1.FileName
Set ex = GetObject(filenam)
sheetnam = Me.txtSheetName.Text
ex.Worksheets(sheetnam).Activate

Set wsSource = ex.ActiveSheet
Set wsNew = ex.Worksheets.Add
srow = 1
scol = 1
srow2 = hrows
scol2 = cols
'srow , scol, srow2, scol2, drow, dcol, wsSource, wsNew
ex.Sheets(wsSource.Name).Select


Set ogn = wsSource.Range(wsSource.Cells(1, 1), wsSource.Cells(srow2,
scol2))
Application.CutCopyMode = False
'Selection.Copy
ogn.Copy


ex.Sheets(wsNew.Name).Select
Set ognto = Range(wsNew.Cells(drow, dcol), wsNew.Cells(drow, dcol))
ognto.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone,
False, False

I also tried:
wsNew.Range(wsNew.Cells(drow, dcol), wsNew.Cells(drow,
dcol)).PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False,
False




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
How can I copy big ranges of cells without drag or copy/paste? Ricardo Julio Excel Discussion (Misc queries) 3 March 23rd 10 02:38 PM
copy paste SQL query result to excel spreadsheet with formatting Juliet Excel Worksheet Functions 1 October 1st 08 07:23 PM
copy & paste spreadsheet cells from excel to outlook to excel mismarple Excel Discussion (Misc queries) 1 September 20th 05 11:16 PM
copy and paste excel spreadsheet into autocad rickr Excel Discussion (Misc queries) 0 July 15th 05 04:41 PM
Copy and Paste ranges between files dude Excel Programming 3 July 23rd 03 01:37 PM


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

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"