Excel WITH statement not working

Hi,I am trying to use LS to format Excel spreadsheet, but with function is giving error: ‘Type Mismatch’.

This line is displaying the error:

With Selection

Heres the code:

Sub Initialize

’ FormatMacro Macro

’ Macro recorded 22/02/2007 by 3M

’

’

Dim Excel As Variant

Dim Exceldoc As Variant



'Activateapp "Microsoft Excel"

'Set Excel = CreateObject("Excel.Application") 'Create Excel object

Set Excel = GetObject(,"Excel.Application")

Set Exceldoc = Excel.ActiveWorkbook 'Get a handle for the active document



Const xlrange =2

Const xlColumns=2

'Const Columns=2

Const xlGeneral=1

Const xlBottom=-4107

Dim Range As Variant

Dim Columns As Variant

Columns = xlColumns



'Excel.Application.Columns("M:M").Select



' FormatMacro Macro

’ Macro recorded 22/02/2007 by 3M

’

’

Excel.Application.Range("M2").Select

With Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.ReadingOrder = xlContext

	.MergeCells = False

End With

Range("M3").Select

Columns("M:M").EntireColumn.AutoFit

Excel.Application.ActiveWindow.SmallScroll ToRight=6

Columns("M:M").Select

With Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = True

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.ReadingOrder = xlContext

	.MergeCells = False

End With

Excel.Application.ActiveWindow.SmallScroll ToRight=0

Selection.Columns.AutoFit

End Sub

Subject: Excel WITH statement not working…

You need to say:

With Excel.Selection

dan

Subject: RE: Excel WITH statement not working…

Thanks Dan,That seems to resolve that problem, no I have illegal function call when debugger is NOT running, see my other post for details…

Here is the other post:

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/ee24a7533bddfa2a8525728a0057a105?OpenDocument