Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel 2000 and vb6

Hi

I have made a program in vb 6 thats open excel and create a worksheet
etc
When a press my Command1 button . it works perfect, But when i close
excel and press my button again i gott this error

"Object variable or With block variable not set"

so can someone help me ?
This is this code it dosen't like

ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-2]:R[4]C[-2],RC[-1])"
.Range("C2").Select
Selection.AutoFill Destination:=.Range("C2:C5"),
Type:=xlFillDefault

CODE

Private Sub Command1_Click()
Dim objXL As Excel.Application
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet

Set objXL = New Excel.Application
Set objWB = objXL.Workbooks.Add
Set objWS = objWB.Worksheets.Application.ActiveSheet

With objWS
.Cells(1, 1) = "HEJ"
.Cells(2, 1) = "1"
.Cells(3, 1) = "1"
.Cells(4, 1) = "4"
.Cells(5, 1) = "7"
.Cells(6, 1) = "3"

.Range("A1:A6").Select
.Range("A1:A6").AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=.Range("B1"), Unique:=True
.Range("C2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-2]:R[4]C[-2],RC[-1])"
.Range("C2").Select
Selection.AutoFill Destination:=.Range("C2:C5"),
Type:=xlFillDefault
End With
objXL.Visible = True

Set objXL = Nothing
Set objWB = Nothing
Set objWS = Nothing

End Sub

//Stelu
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel 2000 and vb6

Hi Stelu

ActiveCell and Selection are not VB6 objects, so they need to be prefixed
with objWS. or in this case just a .

--
HTH. Best wishes Harald
Excel MVP
Followup to newsgroup only please

"Stelu" skrev i melding
om...
Hi

I have made a program in vb 6 thats open excel and create a worksheet
etc
When a press my Command1 button . it works perfect, But when i close
excel and press my button again i gott this error

"Object variable or With block variable not set"

so can someone help me ?
This is this code it dosen't like

ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-2]:R[4]C[-2],RC[-1])"
.Range("C2").Select
Selection.AutoFill Destination:=.Range("C2:C5"),
Type:=xlFillDefault

CODE

Private Sub Command1_Click()
Dim objXL As Excel.Application
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet

Set objXL = New Excel.Application
Set objWB = objXL.Workbooks.Add
Set objWS = objWB.Worksheets.Application.ActiveSheet

With objWS
.Cells(1, 1) = "HEJ"
.Cells(2, 1) = "1"
.Cells(3, 1) = "1"
.Cells(4, 1) = "4"
.Cells(5, 1) = "7"
.Cells(6, 1) = "3"

.Range("A1:A6").Select
.Range("A1:A6").AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=.Range("B1"), Unique:=True
.Range("C2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(RC[-2]:R[4]C[-2],RC[-1])"
.Range("C2").Select
Selection.AutoFill Destination:=.Range("C2:C5"),
Type:=xlFillDefault
End With
objXL.Visible = True

Set objXL = Nothing
Set objWB = Nothing
Set objWS = Nothing

End Sub

//Stelu



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel 2000 and vb6


"Orlando Magalhães Filho" skrev i melding
...

ActiveSheet, ActiveCell and
Selection are Excel application properties, not workbook or worksheet
properties.


Oops. Right you are, my mistake, sorry.

Best wishes Harald
Excel MVP
Followup to newsgroup only please


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel 2000 and vb6


thx Orlando :)

//Stelu

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Excel 2000 and vb6

Help shows activesheet as a property of either application or workbook.

And activecell and selection can belong to a window.

Option Explicit
Sub testme()

Dim wkbk As Workbook
Dim wdw As Window
Dim iCtr As Long

For iCtr = 1 To 2
Workbooks.Add
Worksheets.Add
Range("a1:b99").Select
Worksheets.Add
Range("x5:z7").Select
Next iCtr

For Each wkbk In Application.Workbooks
MsgBox wkbk.ActiveSheet.Name
For Each wdw In wkbk.Windows
MsgBox wdw.ActiveCell.Address
MsgBox wdw.Selection.Address
Next wdw
Next wkbk

End Sub

(No, I've never used them except as properties of Application--except in the
newsgroup).


Harald Staff wrote:

"Orlando Magalhães Filho" skrev i melding
...

ActiveSheet, ActiveCell and
Selection are Excel application properties, not workbook or worksheet
properties.


Oops. Right you are, my mistake, sorry.

Best wishes Harald
Excel MVP
Followup to newsgroup only please


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open 2000 file attachments in Excel 2000 Judy[_2_] Excel Discussion (Misc queries) 2 September 20th 07 10:20 PM
I cannot edit cell format in Excel 2000 (Part of office 2000)! Brett Excel Discussion (Misc queries) 1 April 12th 06 05:58 PM
Using Excel 2000 as Data source for Word 2000 document Malcolm Agingwell Excel Discussion (Misc queries) 2 June 21st 05 09:28 AM
Hyperlink in Excel 2000 can't open bookmarked Word 2000 file DCheslock Excel Discussion (Misc queries) 1 May 5th 05 10:46 PM
Excel Programs developed in Office 2000 on Windows 2000 Trooper Excel Discussion (Misc queries) 4 March 12th 05 11:09 PM


All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"