How to run excel macro from ole
hi to all experts.
i need to run excel macro from ole
Hi,
*& Report ZKC_TEST
*& Description: Fancy report output in XL
*&Programmer: Krishna Chauhan
*&Date: 20 Feb 09
REPORT ZKC_TEST.
* INCLUDES *
INCLUDE ole2incl.
*& TYPES *
TYPES: BEGIN OF ty_marc,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
pstat TYPE marc-pstat,
lvorm TYPE marc-lvorm,
ekgrp TYPE marc-ekgrp,
END OF ty_marc.
TYPES: BEGIN OF ty_titles,
title(20) TYPE c,
field(20) TYPE c,
END OF ty_titles.
*& INTERNAL TABLES *
DATA: t_marc TYPE STANDARD TABLE OF ty_marc,
t_titles TYPE STANDARD TABLE OF ty_titles.
*& FIELD-SYMBOLS *
FIELD-SYMBOLS: <fs_marc> LIKE LINE OF t_marc,
<fs_titles> LIKE LINE OF t_titles,
<fs> TYPE ANY.
*& VARIABLES *
DATA: w_tabix TYPE sy-tabix,
w_titles TYPE sy-tabix,
w_line TYPE sy-tabix,
w_field TYPE string,
filename TYPE string,
path TYPE string,
fullpath TYPE string.
DATA: data_titles TYPE REF TO data.
DATA: e_sheet TYPE ole2_object,
e_activesheet TYPE ole2_object,
e_newsheet TYPE ole2_object,
e_appl TYPE ole2_object,
e_work TYPE ole2_object,
e_cell TYPE ole2_object,
e_color TYPE ole2_object,
e_bold TYPE ole2_object.
*& SELECTION-SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
*& START-OF-SELECTION *
START-OF-SELECTION.
PERFORM get_titles.
PERFORM get_data.
PERFORM create_excel.
*& AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Select archivo'
default_extension = 'xls'
file_filter = '*.xls'
CHANGING
filename = filename
path = path
fullpath = fullpath.
IF sy-subrc EQ 0.
p_file = fullpath.
ENDIF.
*& Form get_titles *
FORM get_titles.
CREATE DATA data_titles TYPE ty_titles.
ASSIGN data_titles->* TO <fs_titles>.
<fs_titles>-title = 'Material'.
<fs_titles>-field = 'MATNR'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Plant'.
<fs_titles>-field = 'WERKS'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'PSTAT'.
<fs_titles>-field = 'PSTAT'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Deletion Flag'.
<fs_titles>-field = 'LVORM'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'EKGRP'.
<fs_titles>-field = 'EKGRP'.
APPEND <fs_titles> TO t_titles.
ENDFORM. "get_titles
*& Form get_data *
FORM get_data.
SELECT matnr werks pstat lvorm ekgrp
INTO TABLE t_marc
FROM marc
WHERE matnr = '000000000001013351'.
ENDFORM. " get_data
*& Form create_excel *
FORM create_excel.
w_line = 1.
CREATE OBJECT e_appl 'EXCEL.APPLICATION'.
SET PROPERTY OF e_appl 'VISIBLE' = 1.
CALL METHOD OF e_appl 'WORKBOOKS' = e_work.
CALL METHOD OF e_work 'Add' = e_work.
GET PROPERTY OF e_appl 'ActiveSheet' = e_activesheet.
SET PROPERTY OF e_activesheet 'Name' = 'Material Plants'.
LOOP AT t_marc ASSIGNING <fs_marc>.
w_tabix = sy-tabix.
w_line = w_line + 1.
LOOP AT t_titles ASSIGNING <fs_titles>.
w_titles = sy-tabix.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = 1
#2 = w_titles.
SET PROPERTY OF e_cell 'Value' = <fs_titles>-title.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_color 'ColorIndex' = 35.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 1.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = w_line
#2 = w_titles.
CONCATENATE '<fs_marc>-' <fs_titles>-field
INTO w_field.
ASSIGN (w_field) TO <fs>.
SET PROPERTY OF e_cell 'Value' = <fs>.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_cell 'ColumnWidth' = 20.
SET PROPERTY OF e_color 'ColorIndex' = 0.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 0.
ENDLOOP.
ENDLOOP.
CALL METHOD OF e_work 'SAVEAS'
EXPORTING
#1 = p_file.
CALL METHOD OF e_work 'close'.
CALL METHOD OF e_appl 'QUIT'.
FREE OBJECT e_appl.
ENDFORM. " create_excel
Similar Messages
-
Running Excel macros from ABAP
Hello everyone,
I am trying to execute an Excel macro from an ABAP program. We are currently on a 46C system. While doing some research on help.sap.com I came across the method execute_macro in class i_oi_document_proxy. Ive never used methods in ABAP before and Im not really sure what Im doing. Has anyone got this to work? When I try to run the program it dumps with error OBJECTS_OBJREF_NOT_ASSIGNED.
Thanks,
Becky
Here is the program:
REPORT ztest_program.
INCLUDE ole2incl.
DATA gs_excel TYPE ole2_object .
DATA gs_wbooks TYPE ole2_object .
DATA gs_wbook TYPE ole2_object .
DATA gs_application TYPE ole2_object .
DATA: h_sheet TYPE ole2_object.
DATA: document TYPE REF TO i_oi_document_proxy.
*Name of the macro in Excel
DATA: macro_string(50) TYPE c
VALUE 'FB03process.FromTheBeginning',
no_flush TYPE c,
param_count TYPE i VALUE 0,
script_name TYPE c VALUE 'X',
error TYPE REF TO i_oi_error
OCCURS 0 WITH HEADER LINE,
retcode TYPE soi_ret_string,
error_string(50) TYPE c,
retvalue(30) TYPE c.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = text-007
EXCEPTIONS
OTHERS = 1.
CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF gs_excel 'Visible' = 1 .
GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
GET PROPERTY OF gs_wbooks 'Application' = gs_application .
*--Opening the existing document
CALL METHOD OF gs_wbooks 'Open' = gs_wbook
EXPORTING #1 = 'D:\temp\FB03process.xls' .
tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
text = text-009
EXCEPTIONS
OTHERS = 1.
GET PROPERTY OF gs_excel 'ACTIVESHEET' = h_sheet.
CALL METHOD document->execute_macro
EXPORTING macro_string = macro_string
param_count = param_count
script_name = script_name
no_flush = no_flush
IMPORTING error = error
retcode = retcode
CHANGING error_string = error_string
retvalue = retvalue.
disconnect from Excel
FREE OBJECT gs_excel.
PERFORM err_hdl.
FORM err_hdl.
IF sy-subrc <> 0.
WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
STOP.
ENDIF.
ENDFORM. " ERR_HDLHi,
Please correct me if I am wrong but it seems that you have not fetched a handle to the document object before issuing the statement CALL METHOD document->execute_macro. Hence the error OBJECTS_OBJREF_NOT_ASSIGNED is being dislayed. If you want to use SAP Desktop Office Integration using ABAP Objects, take a look at this article at http://www.intelligenterp.com/feature/archive/ or http://www.sapinfo.net/public/en/index.php4/article/comvArticle-193333c63b4bd807d2/en/articleStatistic
Hope this helps.
Regards
Message was edited by: Shehryar Khan -
How to run Excel Macros using JDBC-ODBC
Hi,
I want to run the excel macros in the excel file, after I connected to excel file, using JDBC-ODBC bridge.
How macros treated here?
Help needed please..........
- RameshHow to run Excel Macros using JDBC-ODBCYou don't.
As my fuzzy understanding goes.....
Macros (excel, word, etc) run via a "OLE" extension of the script host system.
So the only way to run them is via the OLE interface. That has nothing to do with ODBC. You can write your own JNI to do that, or you might get lucky and find that someone else has written a java library to do it for you. -
How to run excel macros using lookout
Hi,
I want use Excel macros for generating custom reports.Is it possible to run macros using run object in lookout
thanksHi,
I am pretty sure you can activate macros in Excel using the Run object in Lookout. I can think of two ways you can do this:
1. You can setup your Excel to run macros on startup using the Auto_Activate method. In this case, you will just launch excel with your workbook using the Run object and that should run the macros automatically. No brainer!
2. To better control as to when the macros are run we can assign in Excel some shortcut keys for their launching. We then would need to simulate these keystrokes to launch our macros. This can be done using the SendKeys method and some scripting, WHS Scripting for instance. See this pos
t for a scripting example which simulates Alt+Tab keys to bring-to-front an app.
You will launch the script from the Run object and this in turn launches Excel and then simulates the keys for luanching the appropriate macros. I admit this is kinda involved, but hey it works!
Hope this helps,
Khalid -
How to run Excel 2011 from applescript for batch
Every night at 2:00am, I want to convert an Excel spreadsheet to CSV. I'm doing this on a Mac, with Excel 2011. The following Applescript works sometimes:
tell application "Microsoft Excel"
open "/Users/siemsen/PetesLookup/BPO.inventory.current.xls"
save active workbook in "BPO.inventory.current.csv" as CSV file format
close workbook 1 saving no
quit
end tell
With the above script saved in a file named convert.scpt, I can execute it from a bash script using the command "osascript convert.scpt". The bash script runs in a launchd job at 2:00am every day.
It works if Excel is already running on the Mac at the time the cron job runs. If not, it starts Excel, which insists on displaynig a "Excel Workbook Gallery" dialog box. No one is present on the Mac at the time, so no one clicks on the "Cancel" in the dialog box, so the Applescript times out and the cron job fails.
How do I get around this? Can I somehow start Excel without the **** "Excel Workbook Gallery" dialog? Is there some other trick that will allow the job to run unattended?In Excel preferences (general tab) uncheck the checkbox that says "Open Project Gallery when application opens". that should remove the startup dialog.
-
How to call excel macros programmatically in C#?
Hi,
I have a requirement where i need to call excel (2003) macros in C# program. Can anyone help me with a code snippet to do the same?
The excel macro function takes two input parameters? how can the parameters be passed?
Any code snippet to do the same in C# would be helpful.
Thanks.Hey there, Sid. I am tryin gto run your code, but I couldn't even gte it to fire. Here's what I ahve now:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsFormsApplication2
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
//~~> Define your Excel Objects
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
//~~> Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open("C:\\Users\\Ryan\\Desktop\\Coding\\Microsoft Excel\\Work Samples\\Work Samples\\Historical Stock Prices.xlsb");
//~~> Run the macros by supplying the necessary arguments
xlApp.Run("ShowMsg", "Hello from C# Client", "Demo to run Excel macros from C#");
//~~> Clean-up: Close the workbook
xlWorkBook.Close(false);
//~~> Quit the Excel Application
xlApp.Quit();
//~~> Clean Up
releaseObject(xlApp);
releaseObject(xlWorkBook);
//~~> Release the objects
private void releaseObject(object obj)
try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
catch (Exception ex)
obj = null;
finally
GC.Collect();
When I hit the play button nothing happens. When I hot F5 nothing happens. Do you ahve any idea what I'm doing wrong. I'd appreciate any advice with this!!
Thanks!!
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
How to execute Excel Marco from SAP using Office Integration Classes
Is there a way to trigger Excel Macro from SAP? I tried using method CALL METHOD document->execute_macro
of i_oi_document_proxy but it does not work.
Thanks
VivekTry this:
If you are using OLE to populate the Excel Sheet then, then yes you can run a macro.
CALL METHOD OF OBJ_EX_APP 'Run'
EXPORTING #1 = MACROSTR.
Adding a Field Exit
To add a field exit first find the data element that is linked to the screen field- the screen number and program
Run program RSMODPRF. You will need to create two function modules one FIELD_EXIT_MEPO_VENDOR and
FIELD_EXIT_MEPO_VENDOR_A
FIELD_EXIT_MEPO_VENDOR should have code simply of input = ouput.
FIELD_EXIT_MEPO_VENDOR_A should have the code for whatever the functionality is required
Go back to RSMODPRF and run the program without parameters. Use the push buttons to assign the screen, 'A' and program. Use the drop down to activate the field list.
This should now work, but there is no way of debugging. For further information look at OSS 29377
program zzdirlist.
for AIX this method also works.
DATA: BEGIN OF TABL OCCURS 0,
TEXT(80) TYPE C,
END OF TABL.
DATA: COMMAND(256) TYPE C.
COMMAND = 'ls'.
CALL FUNCTION 'RFC_REMOTE_PIPE' DESTINATION 'SERVER_EXEC'
EXPORTING COMMAND = COMMAND
READ = 'X'
TABLES PIPEDATA = TABL.
LOOP AT TABL.
WRITE:/ TABL-text.
ENDLOOP. -
How to run a report from oracle 10g form in .csv format
dear all,
how to run a report from oracle 10g form in .csv format? i've already run in pdf & excel format.
i'm using
SET_REPORT_OBJECT_PROPERTY (ro_report_id, report_desformat, 'PDF'); --for pdf
SET_REPORT_OBJECT_PROPERTY (ro_report_id, report_desformat, 'SPREADSHEET'); ---for excel
Please Help..i have already tried.
but the report show in htm or html format. that file will not save into csv. please help. -
How to run java program from website?
Hello
I'd like to know how to run java program from my web page.
I'd like to push some button in this web page so java program that would be on my server
would pop-up. Can it be done automaticaly upon running this web site? (without any buttons - I just enter website and program pops up).
CheersI rather thought about RMI. But I could try servlets. So how it would look like?.
I would make http request in browser (enter address) and program would show up in its window?. And I would not have to change anything in my program?. This program would run then on both boxes?. One remotely and one not?.
But I would have to learn some basics, I've never worked with servlets. Could you suggest some good sites about it?. With ready examples so I could tweak them to my purpose.
Message was edited by:
macmacmac -
How to run ZAC CDP from a Linux Bundle
Hi all,
I am trying to work out how to run "ZAC CDP" from a Linux bundle. We have 330 Satelites that I need to force the replication of the TFTP folder too in one staggered process.
Is there any reason why this would not work? would a script do it and anyone have a sample?
cheers,
Trev.I would imagine it's possible.
I'm assuming something (run as root user?)
#!/bin/bash
zac cdp
(you may have to put the absolute path in for the location of "zac")
I'm not a linux guru by any means, just that if you can script this via a cron job, I'm sure it can be done via ZCM Bundle. -
How to run db.xml from ORPOS 13.4 version on standalone
Hi All,
How to run db.xml from ORPOS 13.4, We dont have ORBO.
Thanks & Regards
GMGo to the location where your installer is residing and execute the following command:
install.cmd ant install-database
Regards,
Uttam Kumar -
How to run batch file from oracle forms 9i
Hi everyone.
i have a data in csv file. i want to upload it to my database. i am using sql loader for it.
i have made a batch file which run the sql loader and transfer my data to database.
How to run batch file from oracle forms 9i.
when i press the button, nothing uploads in my database. (when i simply run the batch file it works).
here is my code
Begin
HOST('C:\temp\batchfile.bat');
message('done');
end;
Thanks in advance
regards
sajidthis is my log file, when i run manually.
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Jul 1 23:27:53 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: file_to_upload.ctl
There are 2 data files:
Data File: sk.csv
Bad File: sk.bad
Discard File: none specified
(Allow all discards)
Data File: sk1.csv
Bad File: sk1.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table KHAN, loaded from every logical record.
Insert option in effect for this table: APPEND
Column Name Position Len Term Encl Datatype
SR FIRST * , O(") CHARACTER
DATES NEXT * , O(") CHARACTER
AGENT NEXT * , O(") CHARACTER
COUNTRY NEXT * , O(") CHARACTER
TRANSACTIONS NEXT * , O(") CHARACTER
PKR NEXT * , O(") CHARACTER
USD NEXT * , O(") CHARACTER
BANK NEXT * , O(") CHARACTER
Table KHAN:
11088 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 132096 bytes(64 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 11088
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Thu Jul 01 23:27:53 2010
Run ended on Thu Jul 01 23:27:54 2010
Elapsed time was: 00:00:00.63
CPU time was: 00:00:00.17 -
How do run my library from an external drive?
How do run my library from an external drive? I've tried changing destination locations but nothing seems to work. help please
You might find this article useful, there's a section in it on moving to an external drive:
iLounge - Transferring your iTunes Library to Another Drive -
Running Excel macro to format sheet from Labview?
Hey, thanks in advance.
I am trying to put together a VI that can run a macro in Excel. The macro I recorded simply formats some of the cells to be bold, sets the widths/heigths, merges some cells, adds some border, etc. I have been trying to piece together a bunch of examples from the discussion forum, from LV, etc. for doing this with ActiveX. I'm really starting to bang my head on the desk... all I need to do is make all the data my program sends to Excel pretty without having the operator (or supervisor) have to do this manually.
Does anyone have an example of a program that opens a file based on an extension you give it, runs a macro, then closes the file? Or other suggestions for doing this?
All the other examples I've looked at are different enough that I just can't make it work.
Thanks a million!Well adam welcome to the world of active x. One trick I have learned with using it is when I want to do something in the program that uses macros (ie word, excel.) then what I do is create the macro and look at the code, then I will usually duplicate the code in labview using invoke and property nodes just because I do it that way does not mean it is the best way. I do it this way so I do not have to worry about someone deleting the macro. But running the macro is not trivial if you decide to go that route. Here are a bunch of vi's that will help you out.Message Edited by jhoskins on 04-27-2005 09:00 AM
Message Edited by jhoskins on 04-27-2005 09:00 AM
Joe.
"NOTHING IS EVER EASY"
Attachments:
Excel and word toolkit.zip 2013 KB -
How to open excel files from email in macro enabled workbooks NOT 2003-2007 worksheets?
I have recently installed Office 365 and it was working great. I needed to open excel documents via email with the macro enabled option. Yesterday it flicked back to only giving me the option to open in 2003-2007 workbook so now I am having issues with the
macros. I am contracting and trying to get work out and this has now caused huge problems.
Am thinking of uninstalling and reinstalling. I did have older versions of ms office so maybe there is some residual content there to remove? I have tried to change the associations and protocols to open in excel macro enabled workbooks but these tick boxes
are greyed out and I do not know how to gain access to these. Have been hunting all through my computer system but do not know how to do this. Am no expert.
If someone could help I would really appreciate it otherwise will need to find some computer shop expert I suppose...urgently ha.
Thanks in advanceit's sound like excel 13 disable the macros, turn on it will fix your issue.
see here:
http://office.microsoft.com/en-us/excel-help/enable-or-disable-macros-in-office-files-HA010354316.aspx
ps: use the local admin to change the setting, the reason why the setting grey out.
KR
Maybe you are looking for
-
Message sent as iMessage instead of text for iPhone without data
My iPhone does not have data. When I am in a wifi zone iMessage works and texts are received. When I am not in wifi, anyone who sends me a text from an iPhone using iMessage does not come through. Is there a setting where iMessages get automatically
-
Using windows 8 - receive message "ipod detected but cannot be identified properly" when connecting ipod nano 7th gen. Have unisntalled and reinstalled itunes from apple site as advised with no luck. Has anyone else had this problem and resolved it p
-
Hi , I am using WSIF 2.0 to invoke the webservice. Below is my code: public void invoke() try { String wsdlLocation = operationObj.get_wsdl_name(); System.out.println("WsdlLocation:" + wsdlLocation); javax.wsdl.Definition de
-
Warning: mysql_fetch_assoc()
Hi, I have been trying to create a forum using the online Adobe Tutorial . Following is the link : http://www.adobe.com/devnet/dreamweaver/articles/forum_pt3_03.html" My Specifications are: Windows Xp Apache MySql Php I have followed every set of ins
-
EAN number missing leading zeroes
Hi, I have configured two types of EAN/UPC numbers, one being 12 characters and one being 14. In our business, we have a situation where a material has a case UPC number 00099999123456 and a package UPC of 099999123456. When these values are display