• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

VS 2017 de excel açmak

  • Konbuyu başlatan Konbuyu başlatan Orion1
  • Başlangıç tarihi Başlangıç tarihi

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,239
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
 
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:
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
 
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
 
Ancak burada dosya açıksa kapatsın istiyorum.Nasıl bir kod yazmalıyım?
Teşekkür ederim.
 
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
 
Şö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
 
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.
 
Şö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.
 
Geri
Üst