How to use the MergeCells Excel property with Comate.
Thanks
Comate
Re: Comate
Code: Select all
XIncludeFile "COMatePLUS.pbi"
Procedure MergeCells()
Protected.S strCommand
Protected.COMateObject appExcel, xlWorkbook, xlSheet, objRange
Debug "CreateObject"
appExcel = COMate_CreateObject("Excel.Application")
Debug COMate_GetLastErrorDescription()
If appExcel
Debug "Application.Visible=#True"
appExcel\SetProperty("Application\Visible=#True")
Debug COMate_GetLastErrorDescription()
; Workbook
Debug "Workbook"
appExcel\Invoke("Workbooks\Add")
Debug COMate_GetLastErrorDescription()
xlWorkbook = appExcel\GetObjectProperty("Workbooks(1)")
Debug COMate_GetLastErrorDescription()
; Worksheet
Debug "Worksheet"
xlSheet = xlWorkbook\GetObjectProperty("Sheets(1)")
Debug COMate_GetLastErrorDescription()
; Set text in A1.
Debug "Set A1"
xlSheet\SetProperty("Range('A1')\Value = 'Hello, World!'")
Debug COMate_GetLastErrorDescription()
; Merge range A1:B2.
Debug "Merge A1:B2"
strCommand = "Range('A1:B2')"
objRange = xlSheet\GetObjectProperty(strCommand)
Debug COMate_GetLastErrorDescription()
objRange\Invoke("Merge")
Debug COMate_GetLastErrorDescription()
; Tidy up.
Debug "Release Objects"
objRange\Release()
xlSheet\Release()
xlWorkbook\Release()
appExcel\Release()
Else
Debug "Failed to create application object."
Debug COMate_GetLastErrorDescription()
EndIf
EndProcedure
MergeCells()