Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Select Excel Range from Access

Good morning - I have an access query that I output as an excel file.
I would then like to manipulate and format the excel file to my
liking, without manually opening the excel file and running a personal
macro.

As such, I've resorted to putting the macro that works fine in Excel
into Access. I'm getting hung up on the following line of code,
flagged at the bottom with asterisks:

The error is "Run-time error 91 - Object variable or with block
variable not set"

Dim oxlApp As Object
Dim oxlWb As Object
Dim oxlWs As Object

Set oxlApp = CreateObject("Excel.Application")
oxlApp.Visible = True

Set xlWb = oxlApp.workbooks.Open("f:\access\UZOrderReport.xls ")
Set oxlWs = xlWb.Worksheets("qryOrderReporting:15-OrderCross")
oxlWs.Name = "OrderReport"

With oxlApp
.ActiveWindow.Zoom = 85
.Range("o1").Select
***** .Range(.selection, .selection.End(xlToRight)).Select ******
.Selection.ColumnWidth = 6
End With


I've tried the following alterations, to no avail:
..Range(.selection, .selection.End(xlToRight)).Select
or
..Range(selection, selection.End(xlToRight)).Select
or
..Range(.ActiveCell, .ActiveCell.End(xlToRight)).Select

Any ideas?
Thanks,
Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select Excel Range from Access

Dim rng as Object

oxlApp.ActiveWindow.Zoom = 85
set rng = oxlWs.Range(oxlWS.Range("O1"), _
oxlWS.Range("O1").End(-4161 ))
rng.Entirecolumn.ColumnWidth = 6


--
Regards,
Tom Ogilvy

"Brian" wrote in message
m...
Good morning - I have an access query that I output as an excel file.
I would then like to manipulate and format the excel file to my
liking, without manually opening the excel file and running a personal
macro.

As such, I've resorted to putting the macro that works fine in Excel
into Access. I'm getting hung up on the following line of code,
flagged at the bottom with asterisks:

The error is "Run-time error 91 - Object variable or with block
variable not set"

Dim oxlApp As Object
Dim oxlWb As Object
Dim oxlWs As Object

Set oxlApp = CreateObject("Excel.Application")
oxlApp.Visible = True

Set xlWb = oxlApp.workbooks.Open("f:\access\UZOrderReport.xls ")
Set oxlWs = xlWb.Worksheets("qryOrderReporting:15-OrderCross")
oxlWs.Name = "OrderReport"

With oxlApp
.ActiveWindow.Zoom = 85
.Range("o1").Select
***** .Range(.selection, .selection.End(xlToRight)).Select ******
.Selection.ColumnWidth = 6
End With


I've tried the following alterations, to no avail:
.Range(.selection, .selection.End(xlToRight)).Select
or
.Range(selection, selection.End(xlToRight)).Select
or
.Range(.ActiveCell, .ActiveCell.End(xlToRight)).Select

Any ideas?
Thanks,
Brian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Select Excel Range from Access

Tom - thanks for the quick reply. I'm an admitted VBA hack, so pardon
the stupidty of this question:

From what I can tell, you've replaced the excel vba syntax of xlRight
with -4161, correct?

Are there other conventions for xlEnd, xlLeft, etc?

Many thanks,
Brian



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select Excel Range from Access

since you are declaring your variables as Object, this would be an
indication that you are using late binding (not creating a reference to the
Excel object library). In that situation, xlToRight would be an undefined
variant variable (it is defined to have the value -4161 in the object
library of Excel). All constants such as these have an assigned value -
the function sees the assigned value, not the variable name xlToRight. When
you reference the object library you have included implicit code such as

Public Const xltoRight as Long = -4161

But if you use late binding then you have an implicit local declaration in
any place where you use the constant of

Variant xltoRight

If you have infact created the reference, then you can change the -4161 to
xltoright or leave it as is.

You can see the values for constants in the object browser in Excel.

--
Regards,
Tom Ogilvy

"Brian" wrote in message
...
Tom - thanks for the quick reply. I'm an admitted VBA hack, so pardon
the stupidty of this question:

From what I can tell, you've replaced the excel vba syntax of xlRight
with -4161, correct?

Are there other conventions for xlEnd, xlLeft, etc?

Many thanks,
Brian



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select the first cell of the last row in a range - Excel 2003 Gary''s Student New Users to Excel 0 April 2nd 09 12:56 AM
Why does Excel select a range instead of just the cell clicked on Geekette Excel Discussion (Misc queries) 6 March 2nd 09 08:56 PM
Select a range of non-adjacent cells in Excel? hodgsonk Excel Worksheet Functions 12 July 1st 06 04:34 AM
how can i randomly select names from adatabase in excel or access ed wine Excel Discussion (Misc queries) 2 May 5th 06 03:24 PM
How do I select on two variables in a range of data in excel Jeff Excel Worksheet Functions 7 September 13th 05 01:10 AM


All times are GMT +1. The time now is 11:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"