Excell Automation (Selection)

Q1970Q1970 Member Posts: 34
Hi there.

I use Navision 4.00 SP3 and MS Office 2003.

I can't figure out how to access the "selection" property in Excell. To make matters simple, let's assume that I want to set bold fonts on the cells A7, B7 and C7. The Excell macro looks like this.

Range("A7:C7").Select
Selection.Font.Bold = True

My variables look like this

ExcellApp Automation 'Microsoft Excel 11.0 Object Library'.Application
ExcellWorkbook Automation 'Microsoft Excel 11.0 Object Library'.Workbook
ExcellWorksheet Automation 'Microsoft Excel 11.0 Object Library'.Worksheet

My code looks like this

CREATE(ExcellApp);
ExcellApp.Visible(TRUE);
ExcellWorkbook := ExcellApp.Workbooks._Open(FileName);
ExcellWorksheet := ExcellWorkbook.Worksheets.Item(SheetName);
ExcellWorksheet.Activate;
ExcellWorksheet.Range('A7:C7').Select;

And now, at the moment of truth, I hit the wall. I have tried

ExcellApp.Selection.Font.Bold(1);

and

ExcellApp.Selection.Font.Bold := True;

but apparantly I am doing something very very wrong. In both instances, I get the same error message "The return value should be used for this function". The cursor places itself rightafter "Selection".

How big a fool am I, and what should I have done?

Thanks in advance.

/Q

Answers

  • Q1970Q1970 Member Posts: 34
    It never fails, does it. As soon as the post is away, someone waltzes in an shows you how.

    ExcellWorksheet.Range('A7:C7').Font.Bold(1);

    Does the trick.

    I'll get my coat. :oops:

    Have a good one, everybody!
  • MbadMbad Member Posts: 344
    Yup never fails. And ditto.
  • mama Member Posts: 23
    Hi everybody,
    Let me open this old topic for some time, because I've got the same problem. The problem is that I can't use Range here, becasue I need to input some text into the Shape object in Excel.

    Example from excel is:
    ActiveSheet.Shapes("Text 2").Select
    Selection.Characters.Text = "aaa"
    
    In NAV there is no acess to Shapes (as we usually do with the Range) and Shape object itselft does not have methods/properties for changing its value.

    I hope the solution is easy, but can anyone help with it?
Sign In or Register to comment.