Solved

Removing references to Excel - use of xlLeft etc

Posted on 2010-11-27
5
723 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now