Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Merge,Allign cells and create a new work sheet in Excel
Message
From
20/08/1999 08:14:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/08/1999 06:14:35
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00255750
Message ID:
00255778
Views:
13
>I'm having the toughest time figuring out how to merge cells , allign cells (i.e center the text in a merged cell) and create a new worksheet to an existing spreadsheet in excel using Ole automation. Does anyone have any suggestions ?
>Also Does anyone have an example of how the excel header file (Excel.h in your files section ) is used. I dont quite understand when and how to use the constants.
>Is there any documentation/ book that makes more than a passing reference to this OLE stuff--- for a beginner to OLE automation ?
>
>
>Thank you in advance
>Brian

Brian,
I don't know books and unfortunately you discover most of them by yourself.
#include "xlConstants.h" && Whatever the name of .h file
oExcel = createobject("excel.application")
WITH oExcel
  .workbooks.add
  .visible = .t.
  .ActiveWorkBook.Sheets.Add
  WITH .ActiveWorkBook.ActiveSheet
    .Name = "My new sheet"
    .Range("E3").FormulaR1C1 = "Hello There"
    .Range("E3:H3").select
  ENDWITH
  WITH .Application.Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .Merge
  ENDWITH
ENDWITH
Now, help file including all PEM is vbaxl8.hlp and located in ..\Microsoft Office\Office dir. It might not be installed if you haven't chose VB help during installation.
To make the life easier, generally, you first do the steps driectly in Excel recording a macro. Then you get the macro generated code and do some furnishing in VFP. For example you could record macro for the above and compare code. One thing you should keep in mind :
VBA uses named arguments but VFP only positional. That's if a command has the format :
expression.Command(Arg1,Arg2,....ArgN)

In VB (and macro recorded) you could use :
expression.command Arg3 = "Argument 3" Arg6 = 5

This translates to VFP as :
expression.command( , , "Argument 3", , , 5)

Arg1,Arg2, Arg4,Arg5 and Arg7..n should be optional arguments (In help they're defined as Optional variant - variable). Also be carefull about putting the correct object hierarchy for expression. ie: if it's Selection.clear in macro then it's :
oExcel.Appication.Selection.clear
in VFP. Selection applies to application and application is oExcel (little assumption on oExcel naming :)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform