Solved

Removing references to Excel - use of xlLeft etc

Posted on 2010-11-27
5
759 Views
Last Modified: 2012-06-22
I am trying to not have references for excel, word etc on my access project - recommended when dealing with multiple version of excel 12, 14 etc.

I have changed around most of the code so it generically references objects rather than excel and this seems to work fine except one small issue with horizontal alignment.

Simple example  below - horizontal alignment OK if excel reference added but get error if not. Is there a way to set alignment without having the reference to excel?

Dim xlObj As Object
Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Add ' xlFile, , True
Set Sheet = xlObj.ActiveWorkbook.Sheets(1)
Sheet.Range("A2") = 12
Sheet.columns(1).HorizontalAlignment = xlLeft
xlObj.Visible = True
Set Sheet = Nothing
Set xlObj = Nothing
0
Comment
Question by:donhannam
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 34223952
This is an automation of excel from access.
You issue excel commands and set excel object properties from access, hence you need to reference appropriate excel library in access to allow for that.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 34225749
The simplest way is to include definitions for those constants in your Access project. For example, if the xlLeft constant has a value of 0, then you'd need to build a new Constant in your Access project that defines that.

In a Standard Module (not a Form's module), add this in the General Declarations section (the very top of that modules' Code window):

Public Const xlLeft = 0

The drawback to this is that if Microsoft changes the "value" of that constat in future versions, your code could break or produce invalid results. However, the chances of that happening (i.e. MS changing the value of the constant) are very, very remote.
0
 

Author Closing Comment

by:donhannam
ID: 34226198
thanks for this - works perfect

I found the value for xlLeft by trial and error - it is 2.
xlLeft = 2
xlCentre = 3
xlRight = 4
Did not show these in help
0
 
LVL 84
ID: 34229474
Note you can use the Object Browser in the VBA Editor to find the values of these sorts of things. You'll need to have a reference set to the library (which is a good idea during development, since you can then use Intellisense - just be sure to remove it afterward), then do this:

1) Open the Object Browser (F2, or click View - Object Browser, or use the toolbar item)
2) In the Search Box (the second dropdown at the top left of the Object Browser) enter your search term: eg "xlLeft" (without the quotes)
3) Click the binoculars button, or tab out of the field to search.

VBA will show you what it finds, and the value of your constant will be shown at the bottom of the screen.

Note you can also filter the libraries you wish to search by using the top dropdown.

0
 

Author Comment

by:donhannam
ID: 34233132
LSMConsulting: - Thanks - Good pointer - I rarely use the object browser - will use it more.

So I got the values wrong before - 2 is actually left to right? - should be -4131 for xlLeft


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question