Click here to Skip to main content
15,564,350 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Friends,

Here i have error when the data in excel1 paste into the excel2 at specific location. The error is:

"An unhandled exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll Additional information: Public member 'Paste' on type 'Range' not found."

can anyone help me. Below is shows my code.

Can anyone response in fast please...it is really urgent...

VB
Sub Main()

        '~~> Opens Source Workbook. Change path and filename as applicable
        xlWorkBook = xlApp.Workbooks.Open("C:\Users\Thaneskumar\Desktop\Copy of SBL_Release_Yield Loss Update_HL_20150813072418.xlsx")

        MyDate = Format(Now, "dd")
        MyMonth = Format(Now, "MM")
        MyYear = Format(Now, "yyyy")

        Mydirectory = "C:\Users\Thaneskumar\Desktop\test"

        MyExtension = ".xlsx"

        MyFileName = Mydirectory + MyDate + MyMonth + "_" + MyYear + MyExtension

        ExcelApp = CreateObject("Excel.Application")

        xlWorkBook2 = ExcelApp.Workbooks.Add
        ExcelSheet = xlWorkBook2.Worksheets(1)

        '~~> Display Excel
        xlApp.Visible = True

        '~~> Set the source worksheet
        xlWorkSheet = xlWorkBook.Sheets("SBL Trend(daily)")
        '~~> Set the destination worksheet
        xlWsheet2 = xlWorkBook2.Sheets("Sheet1")

        '~~> Set the source range
        xlSourceRange = xlWorkSheet.Range("A18:Q22")
        ''~~> Set the destination range
        xlDestRange = xlWsheet2.Range("A3")

        '~~> Copy and paste the range
        xlSourceRange.Copy()
        xlDestRange.Select()
        xlDestRange.Paste()




        generategraph()
        xlWorkBook2.SaveAs(MyFileName)

        xlWorkBook2.Close()
        xlWorkBook.Close()

    End
Posted
Comments
CgKumar 2-Sep-15 22:14pm    
Hi guys,

i'm settle ready the problem...need to change below line...

'~~> Copy and paste the range
xlSourceRange.Select()
xlSourceRange.Copy()
xlWorkBook.Close()
xlDestRange.Select()
xlDestRange.PasteSpecial()


generategraph()
xlWorkBook2.SaveAs(MyFileName)

xlWorkBook2.Close()

Thanks by the way...;)

1 solution

There's - at least - few differences between VBA and VB.NET programming. Have a look here: Converting Code from VBA to Visual Basic .NET[^]

Follow the link for further details about Range.PasteSpecial[^] method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900