Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I copy big ranges of cells without drag or copy/paste? | Excel Discussion (Misc queries) | |||
copy paste SQL query result to excel spreadsheet with formatting | Excel Worksheet Functions | |||
copy & paste spreadsheet cells from excel to outlook to excel | Excel Discussion (Misc queries) | |||
copy and paste excel spreadsheet into autocad | Excel Discussion (Misc queries) | |||
Copy and Paste ranges between files | Excel Programming |