hmm... onko olemassa mitään yksinkertaista tapaa VB6:lla tarkistaa onko joku tietty excel kirja auki? ja jos on niin kuinka se saadaan "aktiiviseksi" että siihen voi kirjoittaa vb:llä?
MORJENS Arto!
on olemassa aivan uskomattoman yksinkertainen tapa...
'referenssi: Microsoft Excel xx.0 Object Library
Private Sub Command1_Click()
CheckExcel "Työkirja1.xls" 'Esim.
End Sub
Sub CheckExcel(ByVal nimi As String)
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
If InStr(Error$, "ActiveX component can't create object") > 0 Then
MsgBox "Excel ei ole käynnissä"
Else
MsgBox Error$
End If
Set xlApp = Nothing
Err.Clear: Exit Sub
End If
Dim xlBook As Workbook
Dim xlSheet As Worksheet
If xlApp.Workbooks.Count > 0 Then
For Each xlBook In xlApp.Workbooks
With xlBook
If .Name = nimi Then
xlBook.Activate
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1).Value = "JEE"
Set xlSheet = Nothing: Exit For
End If
End With
Next
End If
Set xlApp = Nothing
End Subkiitos Nea...
ei se näköjään ollukkaan ihan perus if juttu... no pureskelen tuota pari päivää =)
Aihe on jo aika vanha, joten et voi enää vastata siihen.