私はこのコードを持っています:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Here we go. All the data in the form to an Excel sheet. Cross your fingers...
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Start a new workbook in Excel- this isn't really what I need though, I need it to open a template and populate it.
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Users\jagtars\Desktop\HI Resources\HI.xlsx")
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets(1)
oSheet.Range("H5").Value = CustomerName.Text
oSheet.Range("K5").Value = dropdown_serverVirtualisation.Value
oSheet.Range("L5").Value = dropdown_desktopVirtualisation.Value
oSheet.Range("M5").Value = dropdown_oracle.Value
oSheet.Range("N5").Value = dropdown_sqlServer.Value
'etc....
'Save the Workbook and Quit Excel
oBook.SaveAs("C:\Users\jagtars\Desktop\HI.xlsx")
MessageBox.Text = "Exported!"
MessageBox.Focus()
oExcel.Quit()
End Sub
このコードは、デスクトップのフォルダからファイルを取得して編集し、新しいファイル「HI」としてデスクトップに保存します。
代わりに、このファイルをプロジェクト フォルダーに配置して参照したいと思います。その後、ユーザーは、新しく変更されたファイルを保存する場所を選択する必要があります。
これを実現するには、コードで何を変更する必要がありますか?
皆さんありがとう。