473,802 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicat ion")
xlBook.Applicat ion.Visible = True
xlBook.Windows( 1).Visible = True
xlBook.Workshee ts("Benefit_Exp ort_Query").Vis ible = True
xlBook.Workshee ts("Benefit Export Query").rows("1 :3").Insert
Shift:=xlDown
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").ColumnW idth = 25
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Value =
[Text41]
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Font.Siz e =
12
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Font.Bol d =
True
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").Horizon talAlignment = xlLeft
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").Vertica lAlignment = xlTop
xlBook.Workshee ts("Benefit Export Query").rows("2 :9999").WrapTex t
= True
xlBook.Workshee ts("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 3410
"apgoodb" <ap*****@yahoo. com> wrote in message
news:86******** *************** **@posting.goog le.com...
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.Applicat ion")
xlBook.Applicat ion.Visible = True
xlBook.Windows( 1).Visible = True
xlBook.Workshee ts("Benefit_Exp ort_Query").Vis ible = True
xlBook.Workshee ts("Benefit Export Query").rows("1 :3").Insert
Shift:=xlDown
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").ColumnW idth = 25
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Value =
[Text41]
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Font.Siz e =
12
xlBook.Workshee ts("Benefit Export Query").Range(" a1").Font.Bol d =
True
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").Horizon talAlignment = xlLeft
xlBook.Workshee ts("Benefit Export
Query").rows("1 :9999").Vertica lAlignment = xlTop
xlBook.Workshee ts("Benefit Export Query").rows("2 :9999").WrapTex t
= True
xlBook.Workshee ts("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
5344
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 able to destroy instances of excel (with the exact same code). I have read many, many posts, and they seem to get bogged down in specifics. So I cribbed this program from the automation help file, simplified it further, so hopefully someone can
17
6349
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
2435
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 and saves it to a folder. The DLL even writes to a log for each step it takes so we can troubleshoot the problems (if any). This works fine on one machine but not another. The folder the DLL is trying to write to has full permissions assigned...
12
3230
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 left running until my application closes. I have tried setting my Excel.Application object to Nothing. I have tried to then fore the GC into action using:
6
598
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 Excel.Range
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9559
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10529
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7596
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4268
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3788
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2964
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.