+ Reply to Thread
Results 1 to 2 of 2

Running a macro outside of Excel

Hybrid View

  1. #1
    Zakynthos
    Guest

    Running a macro outside of Excel

    I want to automatically copy paste individual cells one at a time into
    another program, as I cannot block paste columns from one program to the
    other.

    Is there any way I can configure a macro to operate outside Excel, copy a
    cell, paste into a second program's spreadsheet and repeat this operation for
    a column of figures?



  2. #2
    Registered User
    Join Date
    06-29-2005
    Location
    England
    Posts
    50
    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:

    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:

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1