Questions

VB6 EXCEL 2000 and windows 2000 0x0000000 errror

+
0 Votes
Locked

VB6 EXCEL 2000 and windows 2000 0x0000000 errror

manyon24
Hi i just wrote a small application in vb6 to write data to excel workbook it runs fine on my windows xp machine but i ran the app at work ona win2k machine and straight away get the error "instruction 0x00000000 referenced memory at 0x000000 memory could not be read"
terminate app

Its a little wierd as the machine runs other vb6 apps but this one excel is installed can anyone please help

Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Dim Rng As Excel.Range

Private Sub Command1_Click()
Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)


'the benifit of placing numbers in (row, col) is that you'can loop through different directions if required. I could'have used column names like "A1" 'etc.
Text1.Text = xlsheet.Cells(1, 1) ' row 2 col 1
Text2.Text = xlsheet.Cells(1, 2) ' row 2 col 2
'don't forget to do this or you'll not be able to open'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close False, "c:\book1.xls"

'xl.Quit
End Sub

Private Sub Command2_Click()

Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)

xlsheet.Cells(1, 1) = Text3.Text
xlsheet.Cells(1, 2) = Text4.Text


'just below i used this code to autofit columns
Set Rng = xlsheet.Range("A1", "b1")
Rng.EntireColumn.AutoFit


' Apply borders to the Sales data and headers.
Set Rng = xlsheet.Range("a1", "b1")
Rng.Borders.Weight = xlThin


'save workbook
xlwbook.Save

'don't forget to do this or you'll not be able to open'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close False, "c:\book1.xls"


'xl.Quit
End Sub

Private Sub Command3_Click()

Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)


With Rng

Set Rng = .Find(Text5.Text, After:=.Cells(.Count), LookAt:=xlWhole)
End With
Text6.Text = Rng.Row

xl.ActiveWorkbook.Close False, "c:\book1.xls"


End Sub

Private Sub Form_Load()
Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set Rng = Nothing
Set xlwbook = Nothing
Set xl = Nothing
End Sub