+ Reply to Thread
Results 1 to 13 of 13

Various pasting issues

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Various pasting issues

    Hello everyone.

    I need some help on some pasting issues I have in code (Excel 2007).

    So a user open an excel spreadhseet and a userform pops open. The form has two textboxes and two buttons. In the first textbox a a date (shorthand) is entered. The user presses a button and a file with that date extension is retrieved. Upon opening the file the user is prompted to select an area to copy.

    Set CPSelection = Application.InputBpx(prompt:="Please highlight (or select) the are you want with your mouse", Type:=8)
    CPSelection.Copy
    Now the user goes back to the userform and enters some text in a TextBox. After that she presses a button which creates and opens a new Excel file and is supposed to paste CPSelection.

    With ActiveSheet
    Range("A1")
    CPSelection.pasteSpecial
    End With
    I get two errors on various runs. One informs me that I have a paste method fail. The other informs me that I do not have enough room on the clipboard.

    Any ideas?
    Last edited by AnthonyWB; 05-31-2011 at 11:31 AM. Reason: Issue merged into another problem

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,243

    Re: Various pasting issues

    Hi,

    Look at the examples on http://www.ozgrid.com/forum/showthread.php?p=111223

    You Copy to the clipboard and then go to somewhere else and need to select a cell.
    You need to do a
    Range("A1").Select
    and then do the
    Selection.Paste
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    Correction to my previous post. Actually I do in fact have Range(A1").Select.

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    Actually I am now getting a new error.

    I changed the PasteSpecial to Paste and now encounter an "object Doesn't support this property or method"

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    I have tried to use

    CPSelection.PasteSpecial Paste:=xlPasteValues


    and I recieve a "PasteSpecial method Rangle Class Failed"

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,243

    Re: Various pasting issues

    What is your CPSelection Dimed as? Is it a range of cells? Are you sure?

  7. #7
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    MarvivP

    Its dimes as :

    Dim CPSelection As Range.

    It's done so gloablly. Right below the Option Explicit. Could that be the cause?

  8. #8
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    I am still getting an error here. The first error I get indicates that the paste method is not supported? When I used th immediate window :

    ? CPSelection
    to investigate, it informs me that the "Data on the clipboard is not the same size.......". Any further sugggestions?


    Option Explicit
    Dim CPSelection As Range
    Public Sub CommandButton1_Click()
        Dim Wbk As Workbook
        Dim strFilepath As String
        Dim strASOFDATE As String
        Dim strFilePrefix As String
        Dim strFileFullName As String
         
        strFilepath = "C:\Users\XXXXXXXX\Desktop\YYYYYY\"
        strFilePrefix = "mtm_report_asof_"
    
        strASOFDATE = Me.txtDateBox.Value
        strASOFDATE = Format(Me.txtDateBox.Value, "yyyymmdd")
    
        strFileFullName = strFilepath & strFilePrefix & strASOFDATE & ".xls"
    
        Set Wbk = Workbooks.Open(strFileFullName)
            Worksheets("MTM Detail").Activate
                   
        MsgBox "Please highlight (or select) the area you want with your mouse"
        
        Set CPSelection = Application.InputBox(prompt:="Please highlight (or select) the area you want with your mouse", Type:=8)
        CPSelection.Select
        
        With ActiveSheet
    
        End With
    
    End Sub
    Public Sub CommandButton2_Click()
        Dim strCPName As String
        Dim Wbk As Workbook
        Dim strFilepath As String
        Dim strASOFDATE As String
        Dim strFilePrefix As String
        Dim strFileFullName As String
      
        strFilepath = "C:\Users\XXXXXXXX\Desktop\YYYYYYY\"
        strFilePrefix = "mtm_report_asof_"
        
        strCPName = Me.txtCPNameBox.Value
        
        strFileFullName = strFilepath & strCPName & "_mtm_portfolio_report" & ".xls"
        
        Set Wbk = Workbooks.Add
        Wbk.SaveAs Filename:=strFileFullName
        Set Wbk = Workbooks.Open(strFileFullName)
        
        With ActiveSheet
            Range("A1").Select
            CPSelection.PasteSpecial Paste:=xlPasteValues
        End With
           
    End Sub

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649
    Why copying ?
    Why 2 commandbuttons ?
    Why writing to the same drive where the OS resides ?

    Public Sub CommandButton1_Click()
      c00 = "E:\OF\"
      c01 = txtCPNameBox.Text & "_mtm_portfolio_report.xls"
      c02 = mtm_report_asof_" & Format(txtDateBox.Text, "yyyymmdd") & ".xls"
    
      with workbooks.add
        .saveas  c00 & c01
      end with
      Workbooks.Open c00 & c02
    
      c03 = Application.InputBox("Please highlight (or select) the area you want with your mouse", , , , , , , 8).Address
    
      workbooks(c01).sheets(1).cells(1).resize(range(c03).rows.count,range(c03).columns.count)=workbooks(c02).sheets("MTM Detail").range(c03).value
    End Sub
    Last edited by snb; 05-31-2011 at 12:50 PM.



  10. #10
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    This is impressive but this part is showing up red


      workbooks(txtCPNameBox.Text & "_mtm_portfolio_report.xls").sheets(1).cells(1).resize(range(c01).rows.count,range(c01).columns.count)=
    workbooks(mtm_report_asof_" & Format(txtDateBox.Text, "yyyymmdd") & ".xls").sheets("MTM Detail").range(c01).value

  11. #11
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    So it doesn't quite run. Its indicating that a variable is undefined. But it seems as though all variables are defined?

    Option Explicit
    Public Sub CommandButton1_Click()
      c00 = "N:\XXXXXXXX\Portfolio list\"
      c01 = txtCPNameBox.Text & "_mtm_portfolio_report.xls"
      c02 = "mtm_report_asof_" & Format(txtDateBox.Text, "yyyymmdd") & ".xls"
    
      With Workbooks.Add
        .SaveAs c00 & c01
      End With
      Workbooks.Open c00 & c02
    
      c03 = Application.InputBox("Please highlight (or select) the area you want with your mouse", 8).Address
    
      Workbooks(c01).Sheets(1).Cells(1).Resize(Range(c03).Rows.Count, Range(c03).Columns.Count) = Workbooks(c02).Sheets("MTM Detail").Range(c03).Value
    End Sub
    Now c00 is highlighted in blue, but Public Sub CommandButton1_Click()
    is highlighted in yellow.

  12. #12
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Various pasting issues

    Thanks. I am not sure your code will run. Maybe take a double look at it?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1