Late Binding e.g. to Office, Excel, Word etc
25-Aug-1010 Leave a comment
Option Strict Off
‘Early binding would require COM reference to Excel which brings in
‘ Microsoft.Office.Core
‘ Microsoft.Office.Interop.Excel
‘ Microsoft.Office.Core
‘ Microsoft.Office.Interop.Excel
‘Imports Microsoft.Office.Interop
‘However late binding requires Option Strict Off
Public Class cls
Private Sub CopyClipboardToExcel(Optional ByVal MyNewFileName As String = "")
‘Late Binding or distribute reference
‘http://msdn.microsoft.com/en-us/library/0tcf61s1.aspx
‘Late Binding or distribute reference
‘http://msdn.microsoft.com/en-us/library/0tcf61s1.aspx
Try
‘Dim xlApp As Excel.Application
Dim xlApp As Object = CreateObject("Excel.Application")
Dim xlBook As Object = xlApp.Workbooks.Add
Dim xlSheet As Object = xlBook.Worksheets(1)
‘Dim xlApp As Excel.Application
Dim xlApp As Object = CreateObject("Excel.Application")
Dim xlBook As Object = xlApp.Workbooks.Add
Dim xlSheet As Object = xlBook.Worksheets(1)
xlSheet.Range("A1").Select()
xlSheet.Paste()
Call FormatExcelSheet(xlApp)
xlSheet.Paste()
Call FormatExcelSheet(xlApp)
‘xlSheet.Cells(2, 2) = "This is column B row 2"
xlSheet.Application.Visible = True
xlSheet.Application.Visible = True
If MyNewFileName <> "" Then
xlSheet.SaveAs(MyNewFileName)
‘ Optionally, you can call xlApp.Quit to close the workbook.
End If
xlSheet.SaveAs(MyNewFileName)
‘ Optionally, you can call xlApp.Quit to close the workbook.
End If
Catch ex As Exception
If IsT1 Then
Throw New ApplicationException(ex.Message, ex)
End If
If IsT1 Then
Throw New ApplicationException(ex.Message, ex)
End If
End Try
End Sub
End Class