Solved

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

Posted on 2012-12-28
10
280 Views
Last Modified: 2012-12-28
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
Comment
Question by:Wilder1626
  • 5
  • 3
  • 2
10 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 38726895
Hi,

Shouldn't you refer to TextBox2 on line 12

Regards
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726904
Hi Rgonzo1971

Well the textbox is in a VB6 form and not in Excel.
The texbox name is Text2.
Thanks
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726914
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
 
LVL 142

Expert Comment

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

while stepping through the code, it should become obvious
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 38726920
> this but it past everything on 1 row
is the textbox defined to be "multiline"?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
ID: 38726923
Hi,

Are you sure you have multiline property true

Regards
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726942
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
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726956
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726972
good :)
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38727041
Thanks again for your help

all good now
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now