• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

VB6- Copy a row from excel and paste it in Text2 VB6 issue

Hello all

I'm trying to copy a row from an excel file and paste it in my VB6 project in a Text2 as multiline but i have a hard time with it.

I'm trying this way:
If Text2 <> "" Then
MsgBox "Data already in Textbox"
Else
Dim varData
    If Selection.Rows.Count > 1 Then
        varData = Join(Application.Transpose(Selection.Value), vbCr)
    ElseIf Selection.Columns.Count > 1 Then
        varData = Join(Application.Transpose(Application.Transpose(Selection.Value)), vbCr)
    Else
        varData = Selection.Value
    End If
    With Me.Text2

        .Text = varData
    End With
 End If

Open in new window


But i have this run time error 91.

How can i fix this please?

Thanks again for your help
0
Wilder1626
Asked:
Wilder1626
  • 5
  • 3
  • 2
2 Solutions
 
Rgonzo1971Commented:
Hi,

Shouldn't you refer to TextBox2 on line 12

Regards
0
 
Wilder1626Author Commented:
Hi Rgonzo1971

Well the textbox is in a VB6 form and not in Excel.
The texbox name is Text2.
Thanks
0
 
Wilder1626Author Commented:
I have also tried like this but it past everything on 1 row

Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text2.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the runtime error 91 means "object not set" ...
on which line? on which variable?

while stepping through the code, it should become obvious
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
> this but it past everything on 1 row
is the textbox defined to be "multiline"?
0
 
Rgonzo1971Commented:
Hi,

Are you sure you have multiline property true

Regards
0
 
Wilder1626Author Commented:
Hi angelIII

Yes, the Text2 is set to be Multiline but still pasting on the same row using that code bellow:
Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text2.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

0
 
Wilder1626Author Commented:
I think i had a issue with the textbox itself.

I deleted that textbox and created a new one and called it Text3 with a Multiline yes and now it work with :

Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text3.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
good :)
0
 
Wilder1626Author Commented:
Thanks again for your help

all good now
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now