Results 1 to 7 of 7

Thread: [RESOLVED] Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Resolved [RESOLVED] Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    Hi,

    I am trying to avoid using the Rang("a3").activate method to activatre a reference cell. I have started uisng object variables.

    Have some code here which says when run object required.

    Can someone help debug the code ammendments and where I am going wrong.

    Just copying and pasting between cells and using some text string statements. The routine is getting
    to the left statements below and becoming unstuck - please see the find the comment where error occurred:-


    ' From here program getting confused


    In module


    VB Code:
    1. visual basic code:--------------------------------------------------------------------------------Public FileName As String
    2. [Highlight=VB]Public FileName2 As String
    3. Public length As Integer
    4. Public Length2 As Integer
    5. 'Public xlApp As Object
    6. Public xlApp As Excel.Application
    7. Public wkbobj As Excel.Workbook
    8. Public xlstart As Excel.Worksheet
    9. Public xloutput As Excel.Worksheet
    --------------------------------------------------------------------------------



    In form


    visual basic code:--------------------------------------------------------------------------------
    VB Code:
    1. Dim FileLength As Long
    2. Dim i As Long
    3. Dim arraydata() As String
    4. Dim x As Integer
    5. Dim columns As Integer
    6. Dim j As Integer
    7. Dim FirstGap As Integer
    8. Dim desc As String
    9. Dim pos As Integer
    10. Dim mywbook As String
    11. Dim thiscell As String
    12. Dim thiscell2 As String
    13.  
    14. 'Striping out the path to get the filename
    15.  
    16. frmEBS.txtFileName.Text = FileName
    17. pos = InStrRev(FileName, "\")
    18. mywbook = Mid(FileName, pos + 1, Len(FileName) - pos + 1)
    19.  
    20.  
    21. Set xlApp = Excel.Application
    22. Set wkbobj = xlApp.Workbooks(mywbook)
    23. Set xlstart = wkbobj.Sheets("Starting point")
    24.  
    25.  
    26. xlstart.Range("A2").Copy
    27. 'Worksheets("Output1").Activate - taken out
    28. xloutput.Range("C2").PasteSpecial
    29. xloutput.Range("e2").PasteSpecial
    30.  
    31.  
    32. ' From here program getting confused
    33.  
    34. thiscell2 = xloutput.Cells(2, 5)
    35. If Left(thiscell2, 2).Text = "ND" Or _
    36.    Left(thiscell2, 2).Text = "SD" Or _
    37.    Left(thiscell2, 2).Text = "EBS" Then
    38.    'Don't do anything
    39.    
    40. Else
    41. xloutput.Cells(2, 5) = "EBS-" & thiscell2
    42. End If
    43. xloutput.Cells(2, 5).Copy ' copy one one description to the next description
    44. xloutput.Range("i2").PasteSpecial
    --------------------------------------------------------------------------------[/Highlight]


    Cheers,
    B

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    what is the problem it looks ok?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    Please take into account all the variable posted in previous post. I have also set xloutput as well. It working eal

    VB Code:
    1. Set xloutput = wkbobj.Sheets("Output1")

    It stops at the left and provides an error

    Run time error '424'

    Object required.



    VB Code:
    1. xloutput.Range("C2").Value = xlstart.Range("A2").Value
    2. xloutput.Range("e2").Value = xlstart.Range("A2").Value
    3.  
    4.  
    5. thiscell2 = xloutput.Range("e2").Value
    6.  
    7. 'stops here with error
    8. If Left(thiscell2, 2).Text = "ND" Or _
    9.    Left(thiscell2, 2).Text = "SD" Or _
    10.    Left(thiscell2, 3).Text = "EBS" Then
    11.    'Don't do anything
    12.    
    13. Else
    14. xloutput.Cells(2, 5).Text = "EBS-" & thiscell2
    15. End If
    16. xloutput.Range("i2").Value = xloutput.Range("e2").Value


    Any ideas? I can't see anything wrong with code

    Many thnaks

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    is output1 an existing sheet in the same workbook??
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    yes it was created via code eralier on.

    VB Code:
    1. [B]sheetcount = Worksheets.Count
    2.  
    3. 'Add worksheets after the last sheet
    4. Worksheets.Add After:=Sheets(sheetcount)
    5.  
    6. 'Count Worksheets
    7. sheetcount = Worksheets.Count
    8.  
    9. 'Name the sheet and add the number of sheets
    10. Worksheets(sheetcount).Name = "Output1"
    11.  
    12.  
    13. Set xloutput = wkbobj.Sheets("Output1")
    14.  
    15. xloutput.Range("A1").Formula = "Level"
    16. xloutput.Range("B1").Formula = "Type"
    17.  
    18.  
    19. xloutput.Range("C2").Value = xlstart.Range("A2").Value
    20. xloutput.Range("e2").Value = xlstart.Range("A2").Value[/B]

    don't think this is the problem as the copy and paste code above is working

    as well as put heading titles.

    It stops at the left code with object required. Run time error 424.

    Many thnaks.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    Left(thiscell2, 2).Text = "SD" Or _
    i think this is your problem thiscell2 is your variable, it has no .text property
    VB Code:
    1. Left(thiscell2, 2) = "SD" Or _
    in all instances
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM

    Don't know why you couldn't use .text - the logic? - but it works!

Posting Permissions

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



Click Here to Expand Forum to Full Width