Automate Create Excel File With Late Binding, and Questions

ZaCkOX
07-15-2010, 03:05 PM
I tried to follow the tutorial: http://www.xtremevbtalk.com/showthread.php?t=135815

But I am still a little lost... few questions. First I am using late binding because I am not sure if the client will have Excel installed on their computer. My objective is creating an excel file, and printing the file as landscape. It is optional to open the excel file.

Where I am getting the error:


Set objExcel = CreateObject("Excel.Application") 'ActiveX component can't create object


There is no references correct?

And after I create the excel file, how do I properly assign ranges and change their borders? How do I bold them or merge cells? Been trying to find help on this subject for a few hours, I am only finding help with early-binding.

What I have so far:


'Declare
'Excel
Dim objExcel As Object
Dim objWorkBook As Object
Dim objWorkSheet As Object
'Other
Dim strYear As String
Dim strExcelPath As String

'Announce
strYear = gGetSalesYear(lblTime.Caption) 'Returns 2010
strExcelPath = App.Path & "\SALES\PRINTOUT_2010.xls"

'Create New Excel File
Set objExcel = CreateObject("Excel.Application") 'Error

'Save File And Attributes
'Worksheet Setup
Set objWorkBook = objExcel.Workbooks.Add
Set objWorkSheet = objWorkBook.Worksheets("Sheet1")
'Cell Setup
'How Declare As Range?
'Cell Manipulation
'How To Change The Borders Within The Range? Or Bold? Or Merge?
'Save File
objWorkBook.SaveAs strExcelPath

'Print File
'Still searching

'Empty
'Close Sheets And Books
Set objWorkSheet = Nothing
If Not objWorkBook Is Nothing Then objWorkBook.Close
Set objWorkBook = Nothing
'Leave Application
objExcel.Quit
Set objExcel = Nothing

'Delete File, If Not Being Opened
Kill strExcelPath

ZaCkOX
07-16-2010, 11:31 AM
http://support.microsoft.com/kb/828550

But I was under the belief I could late-bind excel without Microsoft Office installed?

I guess not possible. I must of mis-understood. I guess this is solved, I'll use late-bind with excel installed.

Bob Phillips
07-16-2010, 03:03 PM
If you are binding, late or early, then the product you are binding to MUST be installed, otherwise it is not possible to bind to it. All it means is that you don't have to have a reference to that exe, and so it is possible to easily cater for any version.

One major problem with late binding apart from the performance hit, is that you cannot use the object constants, such as xlColorindexNone.

ZaCkOX
07-19-2010, 06:22 PM
I figured it out, thanks.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum