Imports Microsoft.Office.Core Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.Excel Public Class Form1 'ボタン1でリストボックスにファイル名を取得 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xlApp As Object Dim xlBook As Object Dim xlSheet As Object 'Excel.sheet
ListBox1.Items.Clear() xlApp = GetObject(, "Excel.Application") For Each xlBook In xlApp.Workbooks ListBox1.Items.Add(xlBook.Name) Next
For Each xlSheet In xlApp.sheets ListBox2.Items.Add(xlSheet.Name) Next
End Sub
'リストボックスをクリックで作業中のブック、シート1に画像挿入) Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim xlApp As Object 'Excel.Application Dim xlBook As Object 'Excel.Workbook Dim xlSheet As Object 'Excel.sheet
If ListBox1.Text <> "" Then xlApp = GetObject(, "Excel.Application") xlBook = xlApp.Workbooks.Item(ListBox1.Text) End If