Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing references to Excel - use of xlLeft etc

Posted on 2010-11-27
5
Medium Priority
?
833 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 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

879 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