New problem: Object variable not set

OK managed to Launch Excel OK now (see my last past).

But now I get ‘Object variable not set’ on this line:

Exceldoc.Columns(“M:M”).Select

I also tried

Columns(“M:M”).Select

with the same result…

Here’s 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 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



Exceldoc.Columns("M:M").Select

With Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.ReadingOrder = xlContext

	.MergeCells = False

End With

Exceldoc.Range("M3").Select

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

Exceldoc.ActiveWindow.SmallScroll ToRight=6

Exceldoc.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

Exceldoc.ActiveWindow.SmallScroll ToRight=0

Exceldoc.Selection.Columns.AutoFit

End Sub

Subject: New problem: Object variable not set.

Hello,

Use this

Excel.application.Columns(“B:B”).Select

instead of Exceldoc.Columns(“M:M”).Select

It works for me.

Rgds,

Munish Kaushik

Subject: RE: New problem: Object variable not set.

Thanks for your response.Now, on that same line I get

‘OLE Automation Object Error’

Subject: RE: New problem: Object variable not set.

Hi,

Can you please specify the error number as well? also, Let me know the ersion of the excel you have.

Thanks,

Munish

Subject: RE: New problem: Object variable not set.

Try replacing your old code line -->Exceldoc.Columns(“M:M”).Select

as

Exceldoc.ActiveSheet.Columns(“M:M”).Select

This should work.

Subject: New problem: Object variable not set. New info!

Thanks to all your help, and that of Dan P King, we are nearly there!

Code is now working, but only with LS Debugger on.

Debugger ON - everything works as I planned it, the column I wanted gets formatted a-OK!

Turn off the debugger, and I am getting the Illegal Function call. I can’t tell where! as the error only happens when the debugger is off!

However, I presume it is something to do with the way Excel is called by the program ??

Following code is OK when debugger ON! But gives error when debugger OFF of ‘Illegal Function Call’

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

Const xlHorizontal=-4128

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

’

’

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

With Excel.Selection

	Excel.selection.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	'Excel.selection.ReadingOrder = xlContext

	.MergeCells = False

End With 

Selection=Excel.Application.Range("M3").Select



'Range("M3").Select

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

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

Excel.Application.ActiveWindow.SmallScroll ToRight=6

Exceldoc.ActiveSheet.Columns("M:M").Select

With Excel.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=Excel.Application.Range("M3").Select

'Exceldoc.ActiveSheet.Columns("M:M").EntireColumn.AutoFit

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

End Sub

Does anyone have an idea ??? Thanks so much for all your help so far…

Subject: RE: New problem: Object variable not set. New info!

Hello,

It’s working perfectly at my side.

Please close notes and delete cache.ndk and then start notes again. May be then it works.

Regards,

Munish

Subject: RE: New problem: Object variable not set. New info!

Deleted the cache.ndk.Ran zapnotes as well just in case!

But still, same problem, with the debugger OFF it is giving illegal function call…

Subject: RE: New problem: Object variable not set. New info!

Hi ,

Can you please put an error handler to the code and see which line the error occurs? and let us know…

Regards,

Munish

Subject: RE: New problem: Object variable not set. New info!

See my other post…its fixed now!Just put a go to sleep in!!

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

Subject: RE: New problem: Object variable not set. New info!

Are you sure that it is fixed now?

The Illegal function call is at the line: Activateapp “Microsoft Excel”

You got to replace it with:

Set Excel = CreateObject(“Excel.application”)

If Excel Is Nothing Then

	Msgbox "Error!!! Agent was unable to open Microsoft Excel."

	Exit Sub

End If	



Excel.Workbooks.Add

Set Exceldoc = Excel.Workbooks(1).Worksheets(1)

Exceldoc.Select

You can remove “Selection =”, if you think you are not using it in code to check any condition.

Make sure these lines appear like this —> without ‘Exceldoc’ or ‘Excel.Application’ or ‘Excel.Range’

Excel.ActiveSheet.Range(“M2”).Select

With Excel.Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.MergeCells = False

End With

The one below as this:

Excel.Range(“M:M”).Select

With Excel.Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = True

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.MergeCells = False

End With

Excel.ActiveWindow.SmallScroll ToRight=0

Excel.ActiveSheet.Range("M3").Select

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

This way you see no problems.

Subject: RE: New problem: Object variable not set. New info!

Thanks.I tried your way.

Although there is no errors, the Excel isn’t formatted (at all), it just ignores that.

My way, although there is an error (which goes away if you add sleep command), it actually formats the Excel to…

Here is the code with your lines in; no errors but doesn’t format the Excel:.

Sub Initialize

’ FormatMacro Macro

’ Macro recorded 22/02/2007 by 3M

’

’

Dim Excel As Variant

Dim Exceldoc As Variant

'Sleep 5



Set Excel = CreateObject("Excel.application")

If Excel Is Nothing Then

	Msgbox "Error!!! Agent was unable to open Microsoft Excel."

	Exit Sub

End If 



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

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

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



Excel.Workbooks.Add

Set Exceldoc = Excel.Workbooks(1).Worksheets(1)

Exceldoc.Select



Const xlrange =2

Const xlColumns=2

'Const Columns=2

Const xlGeneral=1

Const xlBottom=-4107

Const xlHorizontal=-4128

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.ActiveSheet.Range("M2").Select

With Excel.Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.MergeCells = False

End With



Selection=Excel.Application.Range("M3").Select



Excel.Range("M:M").Select

With Excel.Selection

	.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = True

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	.MergeCells = False

End With

Excel.ActiveWindow.SmallScroll ToRight=0

Excel.ActiveSheet.Range("M3").Select

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

End Sub

UPDATE !!!******

My code isn’t working either now, it worked fine yesterday now suddenly stopped working…

Subject: RE: New problem: Object variable not set. New info!

Wow. That’s strange. I tested it on then posted. Have no clue what is the problem. So are you sure that your code stopped working after you revert back to your code finally, even with sleep…? Is it not complaining on this line? Selection=Excel.Application.Range(“M3”).Select

Did you forget to comment it out as you are using the same, down below in your code as Excel.ActiveSheet.Range(“M3”).Select

Subject: RE: New problem: Object variable not set. New info!

I think it’s because, two Excel are getting opened.I look in process’s, and Excel is still running.

Just to be clear, I am using the formula code first to export, which opens the instance of Excel I am wanting to format:

Like this:

@Command([FileExport]; “Comma Separated Value”;

“C:\Temp\LOVexport.csv”);

@UpdateFormulaContext;

@Command( [Execute] ;

“C:\Srccode\wins\O2K3\FILES\PFILES\MSOFFICE\OFFICE11\EXCEL.EXE” ;

“C:\Temp\LOVexport.csv” );

@UpdateFormulaContext;

@PostedCommand([ToolsRunMacro];“FExcel”)

I’ll now try your code, but with a small difference:

Remove this line:

Set Excel = CreateObject(“Excel.application”)

Replace with this line:

Set Excel = GetObject(,“Excel.Application”)

However, now it does actually open two Excels (my document, and a new blank one), and gets ‘Select method of worksheet class failed’ on the line:

Exceldoc.Select

Subject: RE: New problem: Object variable not set. New info!

Then back to your code:

Set Excel = GetObject(,“Excel.Application”)

Set Exceldoc = Excel.ActiveWorkbook

This gives no problem with my earlier posted stuff I guess, if you are using ‘GetObject’ instead of 'Exceldoc.Select ’

Subject: RE: New problem: Object variable not set. New info!

Munish!

I have fixed it!

Thanks for your help and that of everyone else!

I decided that, the debugger meant it was running slowly (waiting for me to click something), so I added a Sleep statement…

Its very bizaare! I shouldnt need for him to sleep!

But maybe when he wakes up he notices an Excel thingie!

Sub Initialize

’ FormatMacro Macro

’ Macro recorded 22/02/2007 by 3M

’

’

Dim Excel As Variant

Dim Exceldoc As Variant

Sleep 5



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

Const xlHorizontal=-4128

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

’

’

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

With Excel.Selection

	Excel.selection.HorizontalAlignment = xlGeneral

	.VerticalAlignment = xlBottom

	.WrapText = False

	.Orientation = 0

	.AddIndent = False

	.IndentLevel = 0

	.ShrinkToFit = False

	'Excel.selection.ReadingOrder = xlContext

	.MergeCells = False

End With 

Selection=Excel.Application.Range("M3").Select



'Range("M3").Select

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

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

Excel.Application.ActiveWindow.SmallScroll ToRight=6

Exceldoc.ActiveSheet.Columns("M:M").Select

With Excel.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=Excel.Application.Range("M3").Select

'Exceldoc.ActiveSheet.Columns("M:M").EntireColumn.AutoFit

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

End Sub