VS 2017 de excel açmak

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Merhaba.
VS 2017 de var olan bir exceli aşağıdaki kod ile açmak istiyorum fakat xl.open satırında hata alıyorum.
Nasıl yapmalıyım.
Teşekkür ederim.
Kod:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xl As Object, k As Integer, j As Integer
        xl = CreateObject("Excel.Application")
        xl.open(Application.StartupPath & "\evrentest.xlsx")

    End Sub
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit

Zeki Gürsoy

Uzman
Uzman
Katılım
31 Aralık 2005
Mesajlar
4,225
Excel Vers. ve Dili
Office 2019 (64 bit) - Türkçe
Böyle durumlarda versiyon numarasıyla nesne gelene kadar döngü ile test ettiriyorum.
C#:
on error resume next

for b as byte = 16 to 11 step -1
     xl = createobject("excel.application." & b)
     if not xl is nothing then exit for
next

err.clear
on error goto 0

if xl is nothing then
   '//throw new exception("nesne başlatılamadı")
  msgbox("nesne başlatılamadı")
  exit sub
end if
.
.
Akış sonunda nesneyi serbest bırakmayı ihmal etmeyin. Uygulamanız açık olduğu sürece nesneyi serbest bırakmaz.

C#:
marshal.releasecomobject(xl)
 
Son düzenleme:

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Hocam yanıtınız için teşekkür ederim.
Aşağıdaki gibi yazdım ama yine hata verdi.Open konusunda sıkıntı var gibi.
Kod:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xl As Object, k As Integer, j As Integer
        On Error Resume Next

        For b As Byte = 16 To 11 Step -1
            xl = CreateObject("excel.application." & b)
            If Not xl Is Nothing Then Exit For

        Next
        xl.open(Application.StartupPath & "\evrentest.xlsx")
        Err.Clear()
        On Error GoTo 0

        If xl Is Nothing Then
            '//throw new exception("nesne başlatılamadı")
            MsgBox("nesne başlatılamadı")
            Exit Sub
        End If
        marshal.releasecomobject(xl)

    End Sub
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Merhaba.
Netten aşağıdaki kodları buldum.Çalışıyor.
Kod:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim x1App, x1Book, x1Sheet As Object
        x1App = CreateObject("excel.Application")
        x1App.visible = True
        x1Book = x1App.Workbooks.open(Application.StartupPath & "\evrentest.xlsx")
        x1Sheet = x1Book.sheets(1)
        x1Sheet.range("A1").Value = "Budamı Olmadı."
        x1Book.close(True)
        x1App.quit()
        MsgBox("Veriler Kaydedildi.")
    End Sub
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Ancak burada dosya açıksa kapatsın istiyorum.Nasıl bir kod yazmalıyım?
Teşekkür ederim.
 

veyselemre

Özel Üye
Katılım
9 Mart 2005
Mesajlar
3,553
Excel Vers. ve Dili
Pro Plus 2021
Ancak burada dosya açıksa kapatsın istiyorum.Nasıl bir kod yazmalıyım?
Teşekkür ederim.
Kod:
           For Each p As Process In Process.GetProcesses
                If String.Compare(p.MainWindowTitle.ToString, "Microsoft Excel - Test", True) = 0 Then
                    p.Kill()
                End If
            Next
 

Zeki Gürsoy

Uzman
Uzman
Katılım
31 Aralık 2005
Mesajlar
4,225
Excel Vers. ve Dili
Office 2019 (64 bit) - Türkçe
Şöyle bir şey olabilir...
Kod:
dim testApp
try
testApp = GetObject(Application.StartupPath & "\evrentest.xlsx")
catch ex as exceptin
'kapalı olduğu durumda akış
end try
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
For Each p As Process In Process.GetProcesses
If String.Compare(p.MainWindowTitle.ToString, "Microsoft Excel - Test", True) = 0 Then
p.Kill()
End If
Next
Veyselemre bey teşekkür ederim.
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,254
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Şöyle bir şey olabilir...
Kod:
dim testApp
try
testApp = GetObject(Application.StartupPath & "\evrentest.xlsx")
catch ex as exceptin
'kapalı olduğu durumda akış
end try
Zeki hocam teşekkür ederim.
 
Üst