Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing references to Excel - use of xlLeft etc

Posted on 2010-11-27
5
Medium Priority
?
810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 31

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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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 85
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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.
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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