How do I copy and paste ranges from VB 6.0 in an Excel spreadsheet?

C

Colin Colin

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top