VS 2017 Microsoft.Office.Interop.Excel

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.
Yolu belli bir excel dosyası açmak istiyorum.Ama olmuyor,hata veriyor.
Not : Referansı ekledim.
Kod:
Microsoft.Office.Interop.Excel.Application.Equals = FileOpen(Application.StartupPath & "\evrentest.xlsx")
 

Haluk

𐱅𐰇𐰼𐰚
Katılım
7 Temmuz 2004
Mesajlar
12,270
Excel Vers. ve Dili
64 Bit 2010 - İngilizce
+
Google Sheets
+
JScript
Evren Bey, referans eklemeden şu şekilde yapılabilir...

Kod:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = "C:\TestFolder\Test.xlsx"
        Process.Start(filePath)
End Sub
 

Haluk

𐱅𐰇𐰼𐰚
Katılım
7 Temmuz 2004
Mesajlar
12,270
Excel Vers. ve Dili
64 Bit 2010 - İngilizce
+
Google Sheets
+
JScript
Eğer açmak istediğiniz Excel dosyası, "exe" ile aynı klasördeyse;

Kod:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = Application.StartupPath & "\Test.xlsx"
        Process.Start(filePath)
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
Haluk hocam,teşekkür ederim.Oldu
Şimdide Açılan dosyanın A1 hücresine "Test Evren" yazdırabilirmiyiz.
 

Haluk

𐱅𐰇𐰼𐰚
Katılım
7 Temmuz 2004
Mesajlar
12,270
Excel Vers. ve Dili
64 Bit 2010 - İngilizce
+
Google Sheets
+
JScript
Açmak istediğiniz dosyanın söz konusu klasörde olup olmadığını kontrol ettikten sonra açmak isterseniz;

Kod:
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = Application.StartupPath & "\Test.xlsx"
        If IO.File.Exists(filePath) Then
            MsgBox(filePath & " bulundu")
        Else
            MsgBox(filePath & " bulunamadı")
            Exit Sub
        End If
        Process.Start(filePath)
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
Açmak istediğiniz dosyanın söz konusu klasörde olup olmadığını kontrol ettikten sonra açmak isterseniz;

Kod:
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = Application.StartupPath & "\Test.xlsx"
        If IO.File.Exists(filePath) Then
            MsgBox(filePath & " bulundu")
        Else
            MsgBox(filePath & " bulunamadı")
            Exit Sub
        End If
        Process.Start(filePath)
End Sub
.
Teşekkür ederim,Hocam.
Dosyayı açıyor.
Açılan dosyanın A1 hücresine "Test Evren" yazdırabilirmiyiz?
 

Haluk

𐱅𐰇𐰼𐰚
Katılım
7 Temmuz 2004
Mesajlar
12,270
Excel Vers. ve Dili
64 Bit 2010 - İngilizce
+
Google Sheets
+
JScript
Evren Bey, aşağıdaki gibi deneyin....

Not: Dosya adı ve sayfa adını kendinize göre uyarlarsınız...

Kod:
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = Application.StartupPath & "\Test.xlsx"
        Dim objExcel = New Excel.Application
        Dim myFile As Excel.Workbook
        Dim mySheet As Excel.Worksheet

        If IO.File.Exists(filePath) Then
            MsgBox(filePath & " bulundu")
        Else
            MsgBox(filePath & " bulunamadı")
            objExcel.Quit()
            objExcel = Nothing
            Exit Sub
        End If

        objExcel.Visible = True

        myFile = objExcel.Workbooks.Open(filePath)
        mySheet = myFile.Sheets("Sheet1")
        mySheet.Cells(1, 1) = "Test Evren"
    End Sub
End Class
.
 
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
Haluk hocam teşekkür ederim.
Bende netten aşağıdaki kodları buldum.
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

Microsoft.Office.Interop.Excel ilede nasıl olabilir?Onuda öğrenmek istiyorum?
 

veyselemre

Özel Üye
Katılım
9 Mart 2005
Mesajlar
3,553
Excel Vers. ve Dili
Pro Plus 2021
Kod:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application = Nothing
        Dim xlWorkBook As Excel.Workbook = Nothing
        Dim xlworksheet As Excel.Worksheet = Nothing

        xlApp = New Excel.Application()

        Dim filePath As String = Application.StartupPath & "\Test.xlsx"
        If IO.File.Exists(filePath) Then
            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
            xlWorkBook = xlApp.Workbooks.Open(Application.StartupPath & "\Test.xlsx", 0, False, 5, "", "", True, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", False, False, 0, True, 1, 0)
        Else
            xlWorkBook = xlApp.Workbooks.Add()
        End If

        xlworksheet = DirectCast(xlWorkBook.Worksheets(1), Excel.Worksheet)

        xlworksheet.Cells(1, 1).Value = "Veysel EMRE Test3"
        xlworksheet.Cells(2, 1).Value = "Veysel EMRE Test2"
        For Each huc In xlworksheet.UsedRange.Cells
            MsgBox(huc.Value)
        Next huc

        xlApp.Application.DisplayAlerts = False
        xlWorkBook.SaveAs(filePath)
        xlWorkBook.Close()
        xlApp.Quit()

        Marshal.ReleaseComObject(xlworksheet)
        Marshal.ReleaseComObject(xlWorkBook)
        Marshal.ReleaseComObject(xlApp)
    End Sub
End Class
 
Son düzenleme:

Haluk

𐱅𐰇𐰼𐰚
Katılım
7 Temmuz 2004
Mesajlar
12,270
Excel Vers. ve Dili
64 Bit 2010 - İngilizce
+
Google Sheets
+
JScript
Ancak

Microsoft.Office.Interop.Excel ilede nasıl olabilir?Onuda öğrenmek istiyorum?
Evren Bey, zaten yukarıda 7 No'lu mesajda, referans eklemiştim. Siz başka bir şey mi demek istiyorsunuz?

.
 

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
Sayın veyselemre bey,
Verdiğiniz kod da sorunsuz çalıştı.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
Evren Bey, zaten yukarıda 7 No'lu mesajda, referans eklemiştim. Siz başka bir şey mi demek istiyorsunuz?
Haluk hocam kusura bakmayın,Onu görmemişim.
Sizin kodda sorunsuz çalıştı.
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
Haluk hocam;
Kodlar sonlandırmıyordu(Sizin kodlarda)
Aşağıdaki satırı iptal ettim,
Kod:
'objExcel = Nothing
ve en alta şu 4 satırı yazdım düzeldi.
Kod:
myFile.Save()
        myFile.Close()
        objExcel.Quit()
        'objExcel = Nothing
        Marshal.ReleaseComObject(mySheet)
        Marshal.ReleaseComObject(myFile)
        Marshal.ReleaseComObject(objExcel)
        MsgBox("Veriler excele kaydedildi.")
 
Üst