473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Excel Automation

I have a database that I built some functionality to export a query to
excel and then do some formatting. After reading a lot of comments it
seems I need to use "late binding", because some of the users use 2000
while the others use 2002. This worked using early binding, but after
changing the code to what I thought I needed I have a few errors.
Here is the code:
Dim xlbook as object
Set xlBook = GetObject([txtdirectory], "Excel.Application")
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True
xlBook.Worksheets("Benefit_Export_Query").Visible = True
xlBook.Worksheets("Benefit Export Query").rows("1:3").Insert
Shift:=xlDown
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").ColumnWidth = 25
xlBook.Worksheets("Benefit Export Query").Range("a1").Value =
[Text41]
xlBook.Worksheets("Benefit Export Query").Range("a1").Font.Size =
12
xlBook.Worksheets("Benefit Export Query").Range("a1").Font.Bold =
True
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").HorizontalAlignment = xlLeft
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").VerticalAlignment = xlTop
xlBook.Worksheets("Benefit Export Query").rows("2:9999").WrapText
= True
xlBook.Worksheets("Benefit Export Query").rows("1:9999").AutoFit

The first errors I get are Compile error variable not defined with the
xldown, xlleft, and xltop. However, even if I take these out, nothing
is happening with my workbook. It exports, but no formatting. Any
ideas would be appreciated.
Thanks,
Nov 12 '05 #1
1 3372
"apgoodb" <ap*****@yahoo.com> wrote in message
news:86*************************@posting.google.co m...
I have a database that I built some functionality to export a query to
excel and then do some formatting. After reading a lot of comments it
seems I need to use "late binding", because some of the users use 2000
while the others use 2002. This worked using early binding, but after
changing the code to what I thought I needed I have a few errors.
Here is the code:
Dim xlbook as object
Set xlBook = GetObject([txtdirectory], "Excel.Application")
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True
xlBook.Worksheets("Benefit_Export_Query").Visible = True
xlBook.Worksheets("Benefit Export Query").rows("1:3").Insert
Shift:=xlDown
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").ColumnWidth = 25
xlBook.Worksheets("Benefit Export Query").Range("a1").Value =
[Text41]
xlBook.Worksheets("Benefit Export Query").Range("a1").Font.Size =
12
xlBook.Worksheets("Benefit Export Query").Range("a1").Font.Bold =
True
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").HorizontalAlignment = xlLeft
xlBook.Worksheets("Benefit Export
Query").rows("1:9999").VerticalAlignment = xlTop
xlBook.Worksheets("Benefit Export Query").rows("2:9999").WrapText
= True
xlBook.Worksheets("Benefit Export Query").rows("1:9999").AutoFit

The first errors I get are Compile error variable not defined with the
xldown, xlleft, and xltop. However, even if I take these out, nothing
is happening with my workbook. It exports, but no formatting. Any
ideas would be appreciated.
Thanks,

Although you use late-binding when you hand over the database, you should
always 'cheat' and use early binding first. This will let you use the
constants such as xldown and give the benefit of intellisense to help you
with the Excel object model. When you finally hand it over, you will need t
o remove the reference to Excel, which means that the machine will no longer
recognise these constants.
So before you remove the reference, you could type CTRL-G to get the
immediate window and type in:
Msgbox "xldown = " & xldown
Which shows you that xldown has the value -4121. You could then adjust your
code and put in these constants, or use your own to keep them separate, eg
Const XL_DOWN = -4121.

Fletcher

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
12
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report...
12
by: elziko | last post by:
I'm using late binding (I must) to automate Excel. My code opens Excel after createing and poulating some sheets. My problem is that when the user finally decides to close Excel its process is...
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.