LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running a macro outside of Excel


Yes you can, although the language that you are using needs to be OLE
enabled.

As an example here is a procedure that manipulates an Excel spreadsheet
without the user even seeing Excel at all:


Code:
--------------------

Form Create_Spreadsheet.
*
Constants: c_start_row type XlRow value 7.
*
Data: Excel Type Ole2_Object, " Application
W_Book Type Ole2_Object, " Work book
w_Sheet Type Ole2_Object, " Work Sheet
*
w_ba_count type i, " Max # Business area
w_row type xlRow, " Current ss row.
w_start type XlRangeAddress, " Global format
w_end type XlRangeAddress,
w_range type XlRangeAddress,
w_last type i,
w_last_col type XlColumn.
*
* The number of business areas determines the number of cols in
* the work sheet.
*
Describe table t_tgsb lines w_ba_count.
*
Create Object Excel 'EXCEL.APPLICATION'.
Call Method Of Excel 'WORKBOOKS' = W_Book.
Call Method of w_Book 'Add'.
If sy-subrc = 0.
*
* There may be more than one sheet here - get rid of any other
* sheets
*
Call Method of Excel 'Worksheets' = w_sheet Exporting #1 = 2.
While sy-subrc = 0.
Set Property Of Excel 'DisplayAlerts' = XlFalse.
Call Method of w_Sheet 'Delete'.
Set Property Of Excel 'DisplayAlerts' = XlTrue.
Call Method of Excel 'Worksheets' = w_sheet
Exporting #1 = 2.
EndWhile.
Call Method Of Excel 'Sheets' = w_Sheet
Exporting #1 = 'Sheet1'.
Call Method Of W_sheet 'Activate'.
Set Property of W_Sheet 'Name' = 'Draft Accounts'.
Perform Set_Column_Widths using w_sheet w_ba_count.
Perform SpreadSheet_Headers using w_sheet w_ba_count.
*
* Do some global formatting
*
Describe table t_spreadsheet lines w_row.
Create_Address c_start_row 'B' w_start.
Add 6 to w_row. " For additional totals
Compute_Last_Column w_last w_last w_ba_count w_last_col.
Create_Address w_row w_last_col w_end.
Concatenate w_start w_end into w_range separated by ':'.
Perform Set_Font using w_sheet w_range 'Arial' 7 'Bold'.

--------------------


And so lower level code from one of the procedures:


Code:
--------------------

Form Set_Single_Border Using pu_sheet Type Ole2_Object
pu_range Type XlRangeAddress
pu_LineStyle Type XlLineStyle
pu_Weight Type XlLineWeight
pu_Colour Type XlLineColour
pu_border Type XlBorder.
*
Data: Range type Ole2_Object,
Borders type Ole2_Object.
*
Call Method of pu_Sheet 'Range' = Range Exporting #1 = pu_range.
Call Method of Range 'Borders' = Borders
Exporting #1 = pu_border.
Set Property of Borders: 'Linestyle' = pu_Linestyle,
'Weight' = pu_Weight,
'ColorIndex' = pu_Colour.
*
Free object Borders.
Free object Range.
EndForm.

--------------------



What language are you trying to do this in ? I can perhaps give you
some pointers.

Regards

Rich


--
Rich_z
------------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...o&userid=24737
View this thread: http://www.excelforum.com/showthread...hreadid=384471

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Macro in Excel Randy[_15_] Excel Programming 3 December 6th 04 04:41 PM
Running a excel macro from VB6 Bimal[_3_] Excel Programming 2 February 17th 04 02:37 PM
Excel-Macro running through SQL update. rudolpsh Excel Programming 0 January 22nd 04 12:39 PM
Launch Macro in Access via Macro running in Excel??? dgrant Excel Programming 1 September 24th 03 01:38 PM
Running Excel Macro from VB6 Rick Griffith Excel Programming 2 August 13th 03 07:05 PM


All times are GMT +1. The time now is 08:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"