|
-
Aug 3rd, 2006, 10:29 AM
#1
Thread Starter
Hyperactive Member
[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:
visual basic code:--------------------------------------------------------------------------------Public FileName As String
[Highlight=VB]Public FileName2 As String
Public length As Integer
Public Length2 As Integer
'Public xlApp As Object
Public xlApp As Excel.Application
Public wkbobj As Excel.Workbook
Public xlstart As Excel.Worksheet
Public xloutput As Excel.Worksheet
--------------------------------------------------------------------------------
In form
visual basic code:--------------------------------------------------------------------------------
VB Code:
Dim FileLength As Long
Dim i As Long
Dim arraydata() As String
Dim x As Integer
Dim columns As Integer
Dim j As Integer
Dim FirstGap As Integer
Dim desc As String
Dim pos As Integer
Dim mywbook As String
Dim thiscell As String
Dim thiscell2 As String
'Striping out the path to get the filename
frmEBS.txtFileName.Text = FileName
pos = InStrRev(FileName, "\")
mywbook = Mid(FileName, pos + 1, Len(FileName) - pos + 1)
Set xlApp = Excel.Application
Set wkbobj = xlApp.Workbooks(mywbook)
Set xlstart = wkbobj.Sheets("Starting point")
xlstart.Range("A2").Copy
'Worksheets("Output1").Activate - taken out
xloutput.Range("C2").PasteSpecial
xloutput.Range("e2").PasteSpecial
' From here program getting confused
thiscell2 = xloutput.Cells(2, 5)
If Left(thiscell2, 2).Text = "ND" Or _
Left(thiscell2, 2).Text = "SD" Or _
Left(thiscell2, 2).Text = "EBS" Then
'Don't do anything
Else
xloutput.Cells(2, 5) = "EBS-" & thiscell2
End If
xloutput.Cells(2, 5).Copy ' copy one one description to the next description
xloutput.Range("i2").PasteSpecial
--------------------------------------------------------------------------------[/Highlight]
Cheers,
B
-
Aug 3rd, 2006, 06:57 PM
#2
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
-
Aug 4th, 2006, 05:34 AM
#3
Thread Starter
Hyperactive Member
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:
Set xloutput = wkbobj.Sheets("Output1")
It stops at the left and provides an error
Run time error '424'
Object required.
VB Code:
xloutput.Range("C2").Value = xlstart.Range("A2").Value
xloutput.Range("e2").Value = xlstart.Range("A2").Value
thiscell2 = xloutput.Range("e2").Value
'stops here with error
If Left(thiscell2, 2).Text = "ND" Or _
Left(thiscell2, 2).Text = "SD" Or _
Left(thiscell2, 3).Text = "EBS" Then
'Don't do anything
Else
xloutput.Cells(2, 5).Text = "EBS-" & thiscell2
End If
xloutput.Range("i2").Value = xloutput.Range("e2").Value
Any ideas? I can't see anything wrong with code
Many thnaks
-
Aug 4th, 2006, 05:45 AM
#4
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
-
Aug 4th, 2006, 06:16 AM
#5
Thread Starter
Hyperactive Member
Re: Excel VB6.0 - AVOIDING USING .ACTIVATE PROBLEM
yes it was created via code eralier on.
VB Code:
[B]sheetcount = Worksheets.Count
'Add worksheets after the last sheet
Worksheets.Add After:=Sheets(sheetcount)
'Count Worksheets
sheetcount = Worksheets.Count
'Name the sheet and add the number of sheets
Worksheets(sheetcount).Name = "Output1"
Set xloutput = wkbobj.Sheets("Output1")
xloutput.Range("A1").Formula = "Level"
xloutput.Range("B1").Formula = "Type"
xloutput.Range("C2").Value = xlstart.Range("A2").Value
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.
-
Aug 4th, 2006, 06:33 AM
#6
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:
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
-
Aug 4th, 2006, 07:24 AM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|