Comate

Just starting out? Need help? Post your questions and find answers here.
Bernard
User
User
Posts: 23
Joined: Sun Apr 27, 2003 4:49 pm
Location: France

Comate

Post by Bernard »

How to use the MergeCells Excel property with Comate.

Thanks
Bernard
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Comate

Post by spikey »

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()
Post Reply