ComatePlus + Excel set active sheet

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Deraman
User
User
Posts: 28
Joined: Thu Mar 10, 2016 8:00 am

ComatePlus + Excel set active sheet

Post 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
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ComatePlus + Excel set active sheet

Post 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
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: ComatePlus + Excel set active sheet

Post by davido »

@Deraman,
Thanks for asking the question.

@Shardik
Thank you for the reply.
This will prove very helpful and instructive. :D
DE AA EB
Post Reply