How to run a VB macros code on Query refresh?
Hi BW gurus,
Please help me out with this task.
I have a macros as below
<b>Sub Table_To_Cons()
'Copy the occupied rows
Application.DisplayAlerts = False
TargetSheet = ActiveSheet.Name
Sheets("Table").Activate
j = 2
For i = 21 To 65536
If Range("F" & i).Value = "" Then
'MsgBox "The Cell is Empty"
Else
f = Range("F" & i).Value
g = Range("G" & i).Value
Sheets("Consolidated Data").Range("A" & j).Value = f
Sheets("Consolidated Data").Range("B" & j).Value = g
j = j + 1
End If
Next
Sheets("Consolidated Data").Activate
MsgBox "Finished"
' Update Chart
Sheets("Chart1").Select
ActiveChart.PlotArea.Select
ActiveChart.SetSourceData Source:=Sheets("Consolidated Data").Range("A2:B6") _
, PlotBy:=xlRows
End Sub</b>
User are not interested to run the VB macros manually.
Instead they are asking like this.The macros should run and show the latest result everytime when we refresh the query.
Can someone help me out how to achieve this.
Any kind of help is appreciated.
Thanks in Advance
Have a nice day
Regards
Sam Mathew
Hi Sam,
Very interesting that the Properties dialog has changed. I have no experience with NW2004s. I will answer your questions based on what I do have experience with; then, we will need to do some testing to check my assumptions.
Your first question: does this subroutine already exists in a workbook, or do we have to manually type it in? In the days before Excel 2002, the answer was "yes", the subroutine already exists. Since Excel 2002, the answer is maybe. More often than not, "no" ... and you have to type it in.
But, whether it exists or not, you will find out when I answer yoru second question: exactly where should I search for it? Since you have written a macro, you already know about the Visual Basic Editor (VBE). Since I am not sure how much you know about the VBE, I will explain it as if you know nothing. Please do not be offended.
As a general orientation to the Visual Basic Editor (VBE), there are 4 Windows you want to become familiar with:
1. the Project Explorer Window;
2. the Properties Window;
3. the Object Browser Window; and,
4. the Code Window.
You should see the Project Explorer window on the left side of the VBE. If it is not already visible, make it visible in one of 3 ways:
i. use the VBE menu bar and select View >> Project Explorer
ii. use shortcut keys Ctrl+R
iii. use the VBE Standard toolbar and select the icon for Project Explorer
In the Project Explorer window you can all of the "Projects" (workbooks and add-ins), that are loaded.
In the view of your workbook (the one with the macro) there are at least twol groups of "objects" shown:
Microsoft Excel Objects (these are Worksheets and Workbooks)
Modules (I call these "General Code Modules")
There are two other possible types of objects:
+ Forms
+ Class Modules
Visual Basic Code is always written in a Code Window. There are 3 types of code windows:
i. Object Code Windows
ii. General Code Modules
iii. Class Modules
When you use the Excel macro recorder, it always creates the macro in a General Code Module. The subroutine SAPBEXonRefresh also will be in a General Code Module.
To find it (if it exists), you can start in any code module in your workbook, press Ctrl+F, enter SAPBEXonRefresh, click the radio button to Search in Current Project.
Now, to test my assumptions ... while you are in the Visual Basic Editor, with the Project Explorer Window open, please look under Microsoft Excel Objects and see if there is an object named "SAPBEXqueries". If not, stop right there. I cannot help you.
If the SAPBEXqueries object is there, let me explain what it is. This is a worksheet that is VERY hidden. That means, it is hidden so that it cannot be made visible from Excel. It can only be made visible from the VBE. Let's do not now.
Select the SAPBEXqueries object (double-click), then open the Properties window in the VBE.
You can open the properties window using:
+ View Properties Window
+ press F4
+ use the standard toolbar and click the Properties icon
Look at the Visible property. It should 2 - Very Hidden. Change it to Visible. Now switch back to the Excel view. Look in cell F4. What do you see in this cell? It should be: SAPBEXq0001, or something very similar to that.
Now (still in Excel) open the GoTo dialog (Edit >> Go To; or, press F5). This will list all of the Named Ranges in the workbook. If you are on the SAPBEXqueries worksheet, the GoTo dialog should list a number of Named Ranges starting with SAPBEXq000,,,,, Do you see this?
I am very interested to learn what you see when you do these things. And, I am very willing to answer any questions you have as a result of doing this testing.
By the way, when you make the SAPBEXqueries worksheet hidden again, be careful. As soon as you make it hidden (or very hidden), the selection in VBE will change to an object that is NOT hidden. So, if you are not watching carefully, you might think that you are still on the SAPBEXqueries sheet and that you failed to hide it. And, pretty soon, if you are not careful, you will have hidden every worksheet in the workbook!
- Pete
Similar Messages
-
How to run the open script code from eclipse?
Hi,
How to run the open script code from eclipse.
Please let me any soulutions on this.Hi Konda
I am not quite sure you can do that and it would even be not supported... Again, what is the purpose? Why do you want to run your openscript code in Eclipse?
What is the code you try to run?
As an example, even if you include al the jar files and so on. don't think the function "Launch Browser" could work because it isn't only java code orjar files.....
If you give us more background. maybe we can guide you to a better solution...
JB -
VBA and Bex 7- Event to use in VB code BEFORE Query Refresh ?
Gurus.. is there a Bex Event that I can use to 'intercept' a Refresh Query command to Bex and run some VBA first ? I'm trying to find a way to solve the analysis grid overlap problem when two queries are provided on one Excel worksheet, and navigation takes place.
I've been able to figure out how to bring the results areas together (by deleting blank rows between them), but I'd like to be able to add a chunk of blank rows between analysis grids before the queries actually refresh.Hi Charlie,
if you're interested:
I've found a way to move the areas after the refresh - using the callback event.
The logic is generally:
- Check where analysis-grid for DP1 ends
- Leave some empty lines
- Move the offset of DP2 here.
- Repeat the same for further DP's.
There's only one hatch: I've got some trouble to reactivate the BEx-context-menu after this momvement.
So far I found only the workaround "do another refresh" to solve this issue; that's ok but not 'beautiful'.
Let me know if you need further input.
Maybe you've got an idea for my issue:
I'm looking for a way to execute the a routine only once after refresh - even if there are multiple queries in a workbook.
The problem is that I do not know the order of the query-refresh or any flag that I could use to identifiy the "last query to be processed in this refresh-run".
Kind regards,
Marco -
How to run 64-bit native code with Java Web Start
This question has probably been asked many times, but I couldn't find anything in my searches.
How can I get Java Web Start on a Solaris client (Solaris 10 in this case, with JRE 1.5) to run a java application that includes a 64-bit native code library? The application downloads fine, including the jar file that has the native shared object, but when the native library is loaded by the java application, I get a "wrong ELF class: ELFCLASS64" error.
I assume that is because Web Start is invoking the 32-bit java VM, which can't load a 64-bit library. I tried configuring Java Web Start to use the 64-bit VM (by setting the path to java to ".../jre/bin/sparcv9/java" in the javaws console) but then I get an error that says "Can't load library: .../jre/lib/sparcv9/libdeploy.so".
Does Java Web Start support 64-bit native code, and if so, what do I need to do differently?
Thanks.No it can't. On the Sun download page of the JRE it says that 64 Bit systems need to use the 32 Bit JRE to execute Plugins - this might be the same for Web Start apps.
-
How to run report from java code
I am a begginner in Oracle Reports. We have no AS installed, so we run reports either from Reports Builder or by calling rwrun. I would like to know how to embed report calling into java code , let's say into simple swing application. Some example code would be welcomed. Thanks.
Hello,
You can find examples in :
http://download-uk.oracle.com/docs/cd/B14099_17/bi.1012/b14048/pbr_webservice.htm
Oracle® Application Server Reports Services Publishing Reports to the Web
10g Release 2 (10.1.2)
B14048-02
14 Using the Oracle Reports Web Service
Regards -
How to run and stop LabView code without using start and stop buttons
Hey
I've attached my code that I'm going to use with thermocouples. What I'm trying to do is: when I hit start button the code should run for a minute then stop for 5 minutes and then start again, this process should be repeated twice . Could you please suggest the appropriate way to do it.
Regards
Rajab
Solved!
Go to Solution.
Attachments:
temp. samples.png 24 KBRajab84 wrote:
Hi altenbach
Thanks a lot for your help, I've tried the state machine, I’ve created 5 case structures as following: start for 1 min, stop 5 min, start again for 1 min, stop 5 min, restart again 1 min and finally stop. I’ve tried the code and it didn’t work. Could you please have a look at the attached code and let me if I need to change something. I think I’ve not used the elapsed time function properly.
Best Regards
Rajab
you really dont need to repeat cases (2x)...using a shift register will reset your timer function once the timer has reached it's set limit. the "bool crossing" is used to tell me when the "5 min" case is done and increments the cycle count....ofcoarse, change the "seconds" constant to your desired time on the elapsed timer of this example
and you could "or" the stop to the "compare = 2" or change the select "wait" to "exit" with a constant connected to the stop
Attachments:
Untitled 2.vi 42 KB -
How to call Visual basic MACRO code in ABAP
Hi all,
I created one MACRO in Microsoft office and now i want to call this macro in my ABAP program.
How to do this can anyone provide me the logic for this....
Regards.What Office application/document has the macro? What the other poster was referring to is that you can open any type of Office document, E-mail editor, PDF document, simply by executing the filename or appropriate shell command. By opening the Office document that has the embedded macro, you would trigger that macro to execute. Is that what you need?
Here is a simple example (with a hard-coded filename):
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
DOCUMENT = 'C:\temp\mydoc.doc'
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
SYNCHRONOUS_FAILED = 8
NOT_SUPPORTED_BY_GUI = 9
OTHERS = 10.
As I mentioned, this is also useful for triggering other applications, such as your resident e-mail editor, based on a click of an e-mail address in a GUI screen:
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
DOCUMENT = 'mailto:(put address here)'
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
SYNCHRONOUS_FAILED = 8
NOT_SUPPORTED_BY_GUI = 9
OTHERS = 10. -
How to run the APD programmatically with different query variables
Hi All
I have a requirement to run a APD with a query in it programmatically on a series of posting periods from 1 to 10 I want to run the APD once for each posting period.
Any idea how I can do this.
Thanks
KarenKaren,
Create a variable on posting period in the query.
in tcode RSRT, choose the query name , here you have the option of creating query variants. create different variants and save it.
In APD, when you choose the query, you have the option of choosing query variant, choose the variant you created in rsrt.
You can automate by including the APD with different query variants in a PC.
Sharat -
Hi Tim,
Do you know how to run the WORD macro in RTF?
Suppose I want to run the macro for Section Break, Is there any way we can call it using WORD Macro.
Any help is appriciated.
Thanks,
AmbadasHi Ambadas
Now, Im not entirely sure what you mena by:
'Do you know how to run the WORD macro in RTF?'
Are you looking to run a macro to create a section break for you during the design of the template? - you can do this.
Or do you want to embed a macro in the RTF output - you can not do this - RTF does not support macros.
Please explain further.
Regards, Tim -
How to translate an excel macro to ABAP code
Hi Guys,
My requirement is need to put the subtotaling option w.r.t divison when i download the file to an excel sheet via OLE.
Iam able to get the records in the excel sheet but unable to write the macro in ABAP code.
the macro which i recorded in Excel is
Range("A1:C3").Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
how do i convert this into ABAP code .Pls help. Thanks...
the data might be like
NAME DIVISION AMOUNT
ABC IT 400
DEF BPO 500
HTG IT 400Hi,
You can run an excel macro like this
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
Call Method of h_excel 'WORKBOOKS' = h_mapl.
set property of h_excel 'VISIBLE' = 0.
Call Method of h_mapl 'OPEN'
EXPORTING
#1 = d_file.
CALL METHOD OF H_EXCEL 'ActiveWorkbook' = h_book .
CALL METHOD OF H_book 'Activesheet' = H_sheet .
CALL METHOD OF h_excel 'RUN'
EXPORTING
#1 = ld_macro.
Check the links below as well
http://sample-code-abap.blogspot.com/2009/07/controlling-excel-using-ole-automation.html
http://arthur_ong.tripod.com/xab017.htm -
How to change Crystal Reports XI database name at run time from ASP code using ADO
Dear All,
I need advises regarding to my problem below
I have two database in same SQL 2005 SERVER for TEST01 and LIVE01 Environtment, and I've created more than 100 reports with Crystal Reports 11 and call it from ASP classic page.
The problem is how can I change a database from TEST01 to LIVE01 at the run time from ASP code as I already using TEST01 database on Crystal Reports and I do not want to set a new database location inside crystal for each reports
Thanks and wait for your reply soon.
Below is my code, which has no effect to crystal reports although I've change the database from TEST01 to LIVE01:
<%
Dim oADOConnection, oRptTable, oADORecordset, sql
Dim struser, strpwd, strdriver, dblocation, dbname, strConnect
struser = "sa"
strpwd = ""
strdriver = "{SQL SERVER}"
dblocation = "SQL200501"
dbname = "LIVE01" ' Changed from TEST01 to LIVE01
strConnect = "User Id=" & strUser & ";"
strConnect = strConnect & "PWD=" & strPwd & ";"
strConnect = strConnect & "DRIVER=" & StrDriver & ";"
strConnect = strConnect & "SERVER=" & DBLocation & ";"
strConnect = strConnect & "DATABASE=" & dbName
sql="Select * from Employee"
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application.11")
Set session("oRpt") = session("oApp").OpenReport("C:\REPORTS\RPT01.RPT", 1) 'USING TEST01 DATABASE
session("oRpt").MorePrintEngineErrorMessages = False
session("oRpt").EnableParameterPrompting = False
session("oRpt").DiscardSavedData
Set oADOConnection = Server.CreateObject("ADODB.Connection")
oADOConnection.Open (strConnect)
Set oADORecordset = Server.CreateObject("ADODB.Recordset")
Set oRptTable = session("oRpt").Database.Tables.Item(1)
oRptTable.SetDataSource oADORecordset, 3
session("oRpt").SQLQueryString = CStr(sql)
session("oRpt").ReadRecords
%>Did you ever find a solution to this problem? I have the same problem when moving reports from development to Test to Production environments. If the DBName is not the same the report ignores the name provided at runtime.
-
How to run a .bat code?
how to run a .bat code?
I have a code ,batch (.bat) in richtextbox1, and want , to text(code .bat) in richtextbox1 it was launched in the console cmd
without the use of saving a file with this code and run itIn your code, right-click on the word "Desktop". In the context menu, select "go to definition". The object browser opens. You will see other members of the SpecialFolder enum. You can examine these values and read the description below.
One of them is "ProgramFiles". If you pass this value to GetFolderPath, it returns the path of the program files.
Another way: In your code, move the caret to the word "desktop" and press Ctr+J. It will open the same list of enum values. Whenever you select an item in the list, the tooltip should also show a description of the enum value.
Then look at
System.IO.Path.Combine to combine the program files path with the sub folder path. The result will be the full path of the directory. You can call Path.Combine for every path name or file name that you want to add.
Armin -
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 a command line window from code?
In an application I need to run a dll file with a few arguements. These arguements can be given in the command line window. The execution of the dll file will return a string that i need to get (for the parsing etc).
1. How can I open a command line window from the Java code?
2. How to run commands on it?
3. How to get the results of the commands from the command line into my program?In an application I need to run a dll file with a few
arguements. These arguements can be given in the
command line window. The execution of the dll file
will return a string that i need to get (for the
parsing etc).
A dll is used by other programs. It is not possible to run it from the command line. -
How to close a running exe through java code
hai friends,
i need to close a running exe file through code...
i tried
Runtime r;
Process p;
try {
r = Runtime.getRuntime();
p=r.exec("d:\\aaa");
} catch (IOException ex)
p.destroy();but its not closing the application properly...
pls anyone help meksnagendran26 wrote:
how to exit the application which is running in quick launchWell my guess, since you are not providing specific information, is that java is in fact closing the application that it ran. What you are seeing is some other application that was spawned by whatever it is that you did. And java isn't going to close that because it doesn't even know it exists.
Maybe you are looking for
-
Inputstream.java.io.IOException , applet connection
I'm working on a problem with the failure of a java applet connection to a java servlet. The connection is via the internet, and over port 80. the java console loggin reports the following There was an attempt to redirect a url request, but the attem
-
Hai SAP Guis Can u provide me the T code to take the report for all stock quantities not only the unrestricted use which can be easily exportted to Excel , my client version is 4.5B.If std is not not available please guide me in the querry route . Th
-
Dynamic Report Heading - Classical report
Hi, Could you please let me know how do I change the heading of a classical report based on the user selection on selection screen. I want to display the selection text that the user has selected in the selection screen as the heading for the repor
-
I share PDF files through a secure web application and sporadically encounter this error message when attempting to open/download the shared PDF: I'm the owner of the original files and can open those with no problem. It's only when I save the file
-
The minus button is not working
when i try to imput a negative number the minus button dosent work. have i inadvertently turned it off somehow?