Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA not recognizing the Excel .Selection method 3

Status
Not open for further replies.

rfoye

Programmer
Oct 15, 2004
40
US
I'm formatting an Excel worksheet from Access using VBA. Part of my code is:
Code:
    Set appExcel = New Excel.Application
    Set WB = appExcel.Workbooks.Open(stFile)
    Set WS = WB.Sheets(1)
    
    WS.Range("E:E").Select
    Selection.HorizontalAlignment = xlLeft
    Selection.VerticalAlignment = xlBottom
    Selection.WrapText = False
    Selection.Orientation = 0
    Selection.AddIndent = False
    Selection.IndentLevel = 0
    Selection.ShrinkToFit = False
    Selection.ReadingOrder = xlContext
    Selection.MergeCells = False

On the first line after selecting the range, I get the following error:
Object variable or With block variable Not Set.

What am I doing wrong? I've selected the range, and yet it tells me there is no Selection to work with.

-------------------
Rob Foye
Database Management
Regions Bank
 
Use qualified objects:
Replace all Selection with appExcel.Selection

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



Hi,

Or this...
Code:
    With WS.Range("E:E")
      .HorizontalAlignment = xlLeft
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
   End With
the Select method is not necessary.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top