This is driving me mad, repost Export to Excel probs

Right,further to previous posts, I want

  1. user presses a button;

  2. It provides the export dialogue from a view;

  3. User can select various options;

  4. Whatever the user selects is exported to .csv (or .xls is that possible with @Command)

  5. Some formatting of the Excel occours to make it look nicer.

OK so far?

So I created some code.

Two different scenarios

  1. Run code. When excel opens, click back on notes.

Result=OK. Excel is formatted just like I wanted. Not great for user, as has to click notes then excel;

  1. Run code. Do nothing.

Error 208 Cannot create automation object.

I even checked the registry, and added a .11 as per other posts, and have had a lot of help from forum so far…

But, I need this to work better, user shouldn’t need to suddenly click back on notes for no reason!! and no ‘error 208’ should occour! (and I shouldn’t need to code a Sleep statement!!)

Heres’ the code:

Sub Initialize

’ FormatMacro Macro

’ Macro recorded 22/02/2007 by 3M

’

’

Dim Excel As Variant

Dim Exceldoc As Variant

On Error Goto processError

'Activateapp "CRM Change Management V7 - 9.LOV's Report - Lotus Notes"

'Dim ws As New NotesUIWorkspace

'Dim uidb As NotesUIDatabase

'Set uidb = ws.CurrentDatabase



'Call uidb.OpenView("LOVRep", , True)

Sleep 5





'Activateapp "Microsoft Excel"

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

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



If Excel Is Nothing Then

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

	Exit Sub

End If 

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

processError:

Messagebox "Error " & Err() & ": " & Error()

Exit Sub



'Agent.Run("CommandAgent")

End Sub

'***this is running from a button in a view, the code is the following:

@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”)

Subject: This is driving me mad, repost Export to Excel probs

Let me see if I understand what you’re doing with your code:Data is exported to a CVS

You open Excel

You load the cvs file and run some formatting code.

WAAAAY too much work.

FAQ of FAQs or OLE/FAQ - look for pointers to exporting to Excel and how to create OLE code - just do it directly.

Search here and in the 4/5 forum for ‘Export and excel’ - LOTS of hits.

HTH

Doug

Subject: This is driving me mad, repost Export to Excel probs

As written your code should fail. per the help file:If pathName is the empty string (“”) or is missing, GetObject retrieves the currently active object of the specified class. If no object of that class is active, an error occurs.

You should be using createobject unless you have an active Excel OLE object already.

Also, you’ve given no indication (that I saw) of where the error occurs, but I’m assuming it’s on the getobject line.

Subject: This is driving me mad, repost Export to Excel probs

there’s a really neat and easy Excel exporter in the Sandbox.

http://www-10.lotus.com/ldd/sandbox.nsf/Search?SearchView&Query=excel%20&SearchOrder=1&SearchMax=250&SearchWV=FALSE&SearchFuzzy=FALSE&Start=1&Count=100

or you could invest in Integra4Notes