Page 1 of 1

ComatePlus + Excel set active sheet

Posted: Thu Sep 28, 2017 8:35 am
by Deraman
Dear, I badly need to add sheets and make one of them active using ( ComatePlus + Excel )for transferring data. Please suggest.
Thanks
Dearman

Re: ComatePlus + Excel set active sheet

Posted: Fri Oct 20, 2017 9:27 pm
by Shardik
Falko in the German forum has programmed 96 different PureBasic procedures which call Excel functions using srod's COMatePLUS.PBI. You can download COMatePLUS and ExcelFunktion.pbi from this thread.

For your conveniance I have taken the code of the required procedures to
- Create a new Excel object
- Create a new workbook and save it
- Make Excel visible
- Add a new worksheet
- Rename that worksheet

I have tested the example code below successfully on Windows 8.1 x64 with Microsoft Office 2010 and PB 5.61 x86:

Code: Select all

XIncludeFile "Your/Path/To/COMatePLUS.PBI"

Define ExcelFile.S = GetTemporaryDirectory() + "MyExcelTestFile.xls"
Define ExcelObject.COMateObject

; ----- Create new Excel object
ExcelObject = COMate_CreateObject("Excel.Application")

If ExcelObject
  ; ----- Create new workbook
  ExcelObject\GetObjectProperty("Workbooks\Add")
  SetCurrentDirectory(ExcelFile)

  ; ----- Make Excel visible
  ExcelObject\SetProperty("Visible = #True")

  ; ----- Add new worksheet
  ExcelObject\invoke("Worksheets\Add")

  ; ----- Rename active worksheet
  ExcelObject\SetProperty("ActiveSheet\Name('My new sheet')")
EndIf

Re: ComatePlus + Excel set active sheet

Posted: Fri Oct 20, 2017 10:08 pm
by davido
@Deraman,
Thanks for asking the question.

@Shardik
Thank you for the reply.
This will prove very helpful and instructive. :D