Calling UDF (MS Access) from Excel VBA
Hi,
I need to run a query on an MS Access database that has to perform a weekday calculation between two date columns,
and this query has two date parameters that it receives dynamically. I am using Excel VBA as the front end.
Select AgeRange, count(*) from
(Select IIF(networkdays(date1,date())<=2, "0-2 days","over 2 days")) as AgeRange
from table1
where date2 >= startdt
and date2 <=enddt
) d
group by AgeRange
The actual query is more complex, but this will help illustrate the issue. I build a string variable with
the query, and substitute Startdt and enddt variables with the actual values. I then create a new QueryDef object and get the results from OpenRecordSet.
Except, Networkdays is not a valid function in MS Access. So, this query fails.
I created a WorkDays UDF in MS Access, and used that instead - the query works fine in MS Access, but when
I try to pass it in the QueryDef object, it fails with 3085 error (function not available).
I'm not sure how to get around this, and could use some help.
In summary, I need to run a select query that will calculate weekdays or workdays between two columns (query
is dynamic - dates are variable) from VBA to MS Access, get the results back to VBA so that I can populate the results. Any suggestions are appreciated and welcome.
Thanks!
I tried using datediff with the "w" parameter, but that doesn't work as I had hoped - it gives the
number of weeks between the dates instead of weekdays
I realize that I could get all the data (without doing the group by) down into Excel and then, do the networkdays
formula calculation there, and summarize after that, but that is a very inefficient way - and defeats the purpose of having an access database in the first place. Getting tens of thousands of records is going to cause space issues in Excel too.
Hi Bob,
One solution is to create a table in the Access database storing all the dates in these years, add a column to determine if this date is a week day or not. And create another table to store the dates that are to be excluded from the working days.
In this way, you need to create a separate query to count the valid working days based on the two tables. So the most difficult thing is to create the table that contains all the dates, please check this VBA code snippet which helps you to insert all the
dates into the table.
Sub InsertDatesIntoTable()
Dim StartDate As Date
Dim EndDate As Date
Dim d As Date
Dim w As Integer
Dim IsWorkDay As Boolean
StartDate = #1/1/2015#
EndDate = #12/31/2015#
For d = StartDate To EndDate
Debug.Print d
w = Weekday(d, vbSunday) 'first day of the week is Sunday
If w = 1 Or w = 7 Then ' if the current day is Sunday or Satuday
IsWorkDay = False
Else
IsWorkDay = True
End If
'Here you can insert d and IsWorkDay into the table
Next d
End Sub
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
How to call a labview dll from excel-VBA?
How to call a simple Labview DLL from Excel VBA?
I have seen examples of DLL calls from VB but does it work the same way for VBA? I have 2000 excel and Labview 8.5. I created the DLL and tried to call it from VBA using the same type of code as in NI's website example(ofcourse its a bit diff with 8.5)
http://zone.ni.com/devzone/cda/tut/p/id/...
BUT it errors out when called from excel
ERROR: The object invoked has disconnected from its clientYou would need to provide more details about the LabVIEW DLL, such as the prototypes of the functions (VIs) that you're trying to call, and your actual VBA code. Specifically, what object you're trying to create. You should also make sure the Run-Time Enginer is installed, as well as any required libraries such as the VISA Run-Time if you're using VISA. Have you made sure to enable the ActiveX server for the DLL?
A search yielded the following items that you may wish to peruse:
http://forums.ni.com/ni/board/message?board.id=170&message.id=261345&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=45099&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=299209&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=195846&requireLogin=False -
Acrobat 9.0 Standard. Setting PDF file password from Excel VBA
Acrobat 9.0 Standard. Setting PDF file password from Excel VBA
Hi: I am trying to find a call to set the password of a PDF file that I am creating from Excel Workbook using a VBA call.
I basically have this Excel VBA code that works fine and creates a file.
pBook.PrintOut Copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
PrintToFile:=True, collate:=True, PrToFileName:=PSFileName
' Convert the postscript file to .pdf
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, "", ""
BUT, I need to set the password on this PDF file and do not see an option to do so.
Can you provide a solution for this situation? Appreciate your response in advance.
Thanks.There is no way to set password programmatically using any other dll or any other kit?
I am creating a bunch of PDF files for users programmatically but then they have to go in and set password themselves? This is very inconvenient for users. -
Problem with controlling Annotations from Excel VBA
Hi,
I have a PDF document that has plenty of sticky notes attached to it. These sticky notes have been added by multiple authors on all pages of the document. I am trying to import the contents of these sticky notes, their author and the page number to an excel spreadsheet. I am using Excel 2007 and Acrobat Professional 9.0.
This is the code that I am currently using to import the sticky notes, but the problem that I am facing is that when I run the macro -
Same sticky note contents, author and page numbers are imported multiple times
Not all sticky notes are imported, only some of them appear in the final excel spreadsheet
When I compare the number of sticky notes to that in the original PDF file, the number is correct. But the content is repeated content and that is the reason why only some of the sticky notes are imported.
This is an activity that I need to do on regular basis and the number of sticky notes that I need to import to excel may range between 100 to 200. It is really difficult to do this task manually, so an excel VBA macro could prove really helpful.
Sub ImportComments_Click()
Dim Fpath As String
Dim WordObj As Object
Dim wbkOutput As Excel.Workbook
Dim iRow As Integer
Dim i, j, k As Integer
Dim lRet As Long
Dim objAcroAVDoc As New Acrobat.acroAVDoc
Dim objAcroPDDoc As Acrobat.AcroPDDoc
Dim numPages As Long
Dim lAnnotscnt As Long
Dim Subtype As String
Dim NumComments As Long
Dim AcroApp As Acrobat.AcroApp
Dim objAcroPDPage As Acrobat.AcroPDPage
Dim annot As Acrobat.AcroPDAnnot
Sheets("Defect Log").Select
Range("L3").Activate
Fpath = ActiveCell.Value
Sheets("Defect Log").Select
Range("A1").Activate
i = 0
Do While (Not (IsEmpty(ActiveCell.Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 1).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 2).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 3).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 4).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 5).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 6).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 7).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 8).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 9).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 10).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 11).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 12).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 13).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 14).Value)))
i = i + 1
ActiveCell.Offset(1, 0).Select
Loop
iRow = i + 1
Set wbkOutput = ActiveWorkbook
lRet = objAcroAVDoc.Open(Fpath, "")
Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
numPages = objAcroPDDoc.GetNumPages()
Set objAcroPDPage = objAcroPDDoc.AcquirePage(0)
For k = 1 To numPages
lAnnotscnt = objAcroPDPage.GetNumAnnots()
For m = 0 To lAnnotscnt - 1
If lAnnotscnt = 0 Then Exit For
Set objAcroPDAnnot = objAcroPDPage.GetAnnot(m)
If (objAcroPDAnnot.GetContents <> "" And objAcroPDAnnot.GetSubtype = "Text") Then
Cells(iRow, 5).Value = k
Cells(iRow, 2).Value = objAcroPDAnnot.GetContents()
Cells(iRow, 11).Value = objAcroPDAnnot.GetTitle()
iRow = iRow + 1
End If
Next m
Set objAcroPDPage = objAcroPDDoc.AcquirePage(k)
Next k
lRet = objAcroAVDoc.Close(1)
Set objAcroAVDoc = Nothing
Set objAcroPDAnnot = Nothing
Set objAcroPDPage = Nothing
Set objAcroPDDoc = Nothing
End SubMake sure you are current with 9.x patches, just on general principles.
The code seems fine – nothing jumping out at me.
You can also look at using the JSObject methods and trying this via the JavaScript stuff – that will give you more access to the Annotation information…
From: Adobe Forums <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Date: Thu, 24 Nov 2011 04:25:12 -0800
To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
Subject: Problem with controlling Annotations from Excel VBA
Problem with controlling Annotations from Excel VBA
created by apreeti<http://forums.adobe.com/people/apreeti> in Acrobat SDK - View the full discussion<http://forums.adobe.com/message/4044740#4044740 -
How to read ssas cube and role from Excel vba
Hi,
I want to read all roles and cubes in SSAS Db from Excel Vba.
1. First i want to read all the roles which was assigned to me
2. based on the role, i have to read all cube name
Please help me to
accomplish this task.Hi Jack,
In Analysis Services, Each role contains members, by Windows username or by Windows group, and permissions (read, process, administrator). If the user has the permission to access SSAS database, then the account was contained in one or more roles. When connect
to SSAS database, we need to use an account to log on it, and SSAS will list all the cubes' name based on the role automatically.
Reference
Using Excel to interact with a SSAS cube
Regards,
Charlie Liao
TechNet Community Support -
Doing telnet from excel VBA?
Is it possible to do 'telnet' from excel VBA? The code should get host name/server ip , then username and password from the user. After, it will telnet to the server by providing the username and password...
It should execute some commands in the server too...
Any help appreciableHi,
For coding issue, you can ask the question in the Excel for Developers forum:
http://social.msdn.microsoft.com/Forums/en/exceldev/threads
Best Regards,
Sally Tang -
Call Transaction from Excel VBA macro and download ALV list object results
I have a situation that must be very common u2013 but I canu2019t find any clear information on how to get it done!
We frequently run SAP transactions, download the results (orders or inventory) into Excel, do some calculations and create a spreadsheet report.
I would like to automate this process using Excel VBA so that a macro will perform these steps:
1. Run our custom SAP report "YSD033" that summarizes orders using the previous day as the [From Date] parameter. (The user already has an active ECC 6 R3 session running.) If possible, can the TC be run using a specific variant "G111BIZ" ?
2. Download the list object that appears in an ALV grid as a table to an empty spreadsheet in the active workbook (export XXL list object)
3. Save the resulting workbook and close Excel.
Should the solution use u201Ccall transactionu201D or a GuiXT script?
Any help would be much appreciated, and some sample VBA code would be great!
Thanks.
GlennGood suggestion, but
I get "permission denied" for SapGuiAuto.GetScriptingEngine
I also tried the method below, but received this RFC error message:
User PPPPPPP has no RFC authorization for function group SYST.
Sub LoginCheck()
If login = False Then
' Setting the necessary variables for R/3 connection
Set objBAPICortrol = CreateObject("SAP.Functions")
Set objConnection = objBAPICortrol.Connection
' Establish a connection
If objConnection.Logon(0, False) Then
login = True
MsgBox "Connection Established"
CommandButton1.Caption = "Disconnect"
End If
Else
CommandButton1.Caption = "Connect 2 SAP"
login = False
objConnection.Logoff
Set objConnection = Nothing
Set objBAPICortrol = Nothing
End If
End Sub
I was told that these kinds of authority open up too big of a window that can't be monitored adequately...
I'm considering an approach like what is below if I can't convince security to grant me permissions...
Application.Wait Now + TimeValue("00:00:01")
SendKeys EnterKey, False
Since blocked RFC security settings are preventing the solution from being installed, I am markgin this question as answered.
I will post different questions about 1. how to convince the security team that it will be safe to allow the use of RFC calls, and /or 2. how use some windows-level scripting code to run the SAP jobs.
Thanks.
Edited by: GlennWebster on Mar 1, 2010 4:34 PM -
Need to checkout MS Project file from Excel VBA
I have a VBA Excel macro that can open an MS Project file, and extract data. It works fine when the MS Project file is on my hard drive or other location where no check out is required. But often the MPP files I need to access are stored in SharePoint,
in document libraries, that have checkin/checkout enabled. I am aware of the the way to do this for an Excel file, such as the following code snippet.
' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(Filename:=docCheckOut) = True Then
Workbooks.CheckOut (Filename:=docCheckOut)
Else
MsgBox "You are unable to check out this document at this time."
End If
I need to be able to do the same thing for MPP files. Here is the code I have; however, I get a compile error on the CheckOut line, indicating "wrong number of arguments or invalid property assignment". My research suggests that I should
get this compile error, as it only works on certain collections. Even the line containing "CanCheckOut", while it does not give me a compile or run time error, it does not return the proper response.
Dim mpApp As MSProject.Application
Set mpApp = New MSProject.Application
AppActivate "Project Professional"
' Determine if mpp file can be checked out.
If mpApp.CanCheckOut(mppFileToOpen) = True Then
mpApp.CheckOut (mppFileToOpen)
Else
MsgBox "Unable to check out this document at this time."
End If
Is there a way to checkout an MS Project file stored in SharePoint from within Excel VBA? Thanks.
RayRod,
Thanks very much. This was, indeed, the solution. Don't know how I could have missed this.
I did run into some issues with ensuring proper object references, checking back in, and being able to handle files that may be on a laptop, SharePoint site with checkout requirements, or SharePoint site without checkout requirements. Also faced an
issue checking back in; part of my macro opens the MPP file (that is checked out), acquires various pieces of data, then runs a macro in the MPP file that exports data to an excel spreadsheet. After this macro runs (does a save-as using a map), check
in is no longer possible. Fortunately, I could checkout the MPP file, open it, get all the required data elements, make a few changes to the MPP file, check it back in (but not close), then run the macro, then close without saving. In the end,
it all works like a champ. Thanks very much for your advice.
Ray -
How to call Copy.GetItem Method in Excel vba function
Hi,
I want to use sharepoint copy services to download/upload or retreive field information of a sharepoint file.
For that i want to sharepoint web services. One class among them is copy. I want to call the GetItem method present in that class.
Think that modules are not installed or not found in excel vba editor tools reference library list to enable.
So please provide me the steps from scratch to install the sharepoint library. and call the Copy class methods in my script.
Just send me a sample vba code to accomplishes the same requirement. I appreciate the help.
Regards,
SUBBAHi SUBBA,
The following articles for your reference:
VBA - Download files from sharepoint
http://ckannan.blogspot.com/2012/09/vba-download-files-from-sharepoint.html
Using Microsoft Windows SharePoint Services with the Microsoft Office System
http://msdn.microsoft.com/en-us/library/office/aa159897(v=office.11).aspx
How to download a file from a Sharepoint server via Excel VBA?
http://www.justanswer.com/computer-programming/7ntq7-download-file-sharepoint-server-via-excel-vba.html
About the Excel VBA questions, you can also post it to Excel for Developers Forum, you will get more help and confirmed answers from there.
http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev<o:p></o:p>
Best Regards
Dennis Guo
TechNet Community Support -
Powershell Variable from Excel.VBA Macro
Hi Guys!
I don't know if what i'm asking you is achievable.
I've learned how to pass variables/arguments from powershell to Excel/VBA Macro but i need to do the opposite thing.
This is an example of what i want:
Powershell
Excel/VBA Macro
$Input=1 ----------------------------------------------------------------> Sub Macro(input)
$excel.Run("Macro",$Input)
Output=input +6
$output (Expected 7) <---------------------------------------------------- return Output
I don't know how to do this can you help me please?
AOk guys those are the script.
Macro:
Sub CreatePWD()
Dim PWD As String
Dim i As Integer
Dim Max As Integer
Dim F1 As Worksheet
Set F1 = ThisWorkbook.Worksheets("Foglio1")
Max = F1.Range("A1").Value
For i = 1 To Max
If Int((2 * Rnd) + 1) = 1 Then
PWD = PWD & Chr(Int((90 - 65 + 1) * Rnd + 65))
Else
PWD = PWD & Int((9 - 0 + 1) * Rnd + 0)
End If
Next i
MsgBox PWD
End Sub
Powershell:
$Excel = New-Object -ComObject excel.application
$Excel.visible=$false
$Version = "C:\Users\Alberto Corona\Desktop\Cartel1.xlsm"
$WorkBook= $Excel.workbooks.open($Version)
$WorkSheet= $WorkBook.worksheets.item(1)
$WorkSheet.cells.item(1,1)=5
$Excel.Run("CreatePWD")
$WorkBook.save()
$WorkBook.close()
$Excel.quit()
The result of macro is like "52UT7" i want a variable in powershell called $PWD that contain the value of the macro.
Hope the problem is clear now.
Thanks
A -
Download Data From Excel - VBA Code to SAP Using BDC
Hi ,
I am Sudhir Dure, working with Satyam Computers.
I need help on the below query:
I have an excel file which download data from Excel to SAP using RFC function & with the help of VBA interface.
In this VBA code I have used BDC recording of SAP Transaction KE21N to post data into SAP.
Now I am facing problem to find sub screen (tab page screen ) in SAP from VBA code .
How to pass BDC Subscreen details from VBA code to SAP using below code?
BDCTABLE.Rows.Add
BDCTABLE.Cell(J, "PROGRAM") = PROGRAMNAME
BDCTABLE.Cell(J, "DYNPRO") = "0200"
BDCTABLE.Cell(J, "DYNBEGIN") = "X"
BDCTABLE.Cell(J, "FNAM") = "BDC_OKCODE"
BDCTABLE.Cell(J, "FVAL") = "=NEXT"
Thanks,
Sudhir Dure
9972097464can anyone tell me how to get the PurchaseOrder number and item quantity from the Salesorder...? what are the fields here as given below..??
For Each oItem In oSalesOrder.items
wsTemplate.Range(cols(3) & Indexv).Value = oItem.material.material
'wsTemplate.Range(cols(4) & Indexv).Value = ' I need item quantity here ????
wsTemplate.Range(cols(1) & Indexv).Value = sapSoNumber
wsTemplate.Range(cols(2) & Indexv).Value = ' I need purchase order number here>???
Indexv = (Indexv + 1)
Next
reply fast. please .. thanks -
Non-English string access from excel sheet through JDBC
My excel sheet data is
Test ������������
I am using JDBC connectivity for accessing the Excel sheet.
Code looks like,
List Output = new List();
try
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:qa-list", "", "" );
stmnt = c.createStatement();
ResultSet rs = stmnt.executeQuery("select * from [Sheet1$];");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int i=1; i <= numberOfColumns; i++){
Output.add(rsmd.getColumnLabel(i));
catch( Exception e )
System.err.println( e );
finally
try
stmnt.close();
c.close();
catch( Exception e )
System.err.println( e );
Now. I am showing those data into the table(JTable) Applet programming.
For, English string it is showing properly but, for non-English string are showing �???????????????????�
I would like to know what could be the reason.
Addional info:
ava version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
If possible please send some reference code .I have one excel sheet which having differenct countries specific meaining of common words.
I am using JDBC connectivity for accessing that Excel sheet.
Code looks like,
List Output = new List();
try
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:qa-list", "", "" );
stmnt = c.createStatement();
ResultSet rs = stmnt.executeQuery("select * from [Sheet1$];");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int i=1; i <= numberOfColumns; i++){
Output.add(rsmd.getColumnLabel(i));
catch( Exception e ){
System.err.println( e );
finally{
try{
stmnt.close();
c.close();
catch( Exception e ){
System.err.println( e );
Now. I am showing those output data into the table(JTable) in my Applet programming.
For, English string it is showing properly but, for non-English strings are showing question marks like, �?????�
I would like to know what could be the reason.
Please help me, i am stuck in my project. -
Send SMS from excel (VBA)
I need help to find a solution that always works to my current problem:
Using Excel 2007 VBA I need to send a similar text message to say 50-100 people using Nokia PC suite. Has anyone found a way of doing this?
I have found a way of opening and then initially controlling PC Suite in VBA by using sendkeys, however it always falls over at some point as it loops through all the staff.
Scenario is simple - I have built a rota for where I work. Each employee receives an email with their rota in it for the coming week; I also want to send a short text message to each employee telling them that their rota is in their email inbox and details of their next shift.
So, the VBA code loops through each staff member, customises the text message contents but always falls over for no apparent part way through the loop. I have succeeded in getting it to work for 5 people, but it falls over when it gets into double figures.
I could get it to send bundles of 5 but there must be an easier way; someone must have tried doing what i'm doing and succeded!
ThanksHi,
I would like to know the way in which I can achieve the above. i.e. Send SMS from Excel. even 2-5 sms will work for me..
Thanks... -
BAPI Access from Excel using VBA
Im writing an excel macro (VBA) to call a bapi that populates a spreadsheet.
The user will then do some manipulation of the data collected, and then it must be sent back to sap.
The Bapi in question is BAPI_GET_USER_DETAIL
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" EXPORTING
*" VALUE(LOGONDATA) LIKE BAPILOGOND STRUCTURE BAPILOGOND
*" VALUE(DEFAULTS) LIKE BAPIDEFAUL STRUCTURE BAPIDEFAUL
*" VALUE(ADDRESS) LIKE BAPIADDR3 STRUCTURE BAPIADDR3
*" VALUE(COMPANY) LIKE BAPIUSCOMP STRUCTURE BAPIUSCOMP
*" VALUE(SNC) LIKE BAPISNCU STRUCTURE BAPISNCU
*" VALUE(REF_USER) LIKE BAPIREFUS STRUCTURE BAPIREFUS
*" VALUE(ALIAS) LIKE BAPIALIAS STRUCTURE BAPIALIAS
*" TABLES
*" PARAMETER STRUCTURE BAPIPARAM OPTIONAL
*" PROFILES STRUCTURE BAPIPROF OPTIONAL
*" ACTIVITYGROUPS STRUCTURE BAPIAGR OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*" ADDTEL STRUCTURE BAPIADTEL OPTIONAL
*" ADDFAX STRUCTURE BAPIADFAX OPTIONAL
*" ADDTTX STRUCTURE BAPIADTTX OPTIONAL
*" ADDTLX STRUCTURE BAPIADTLX OPTIONAL
*" ADDSMTP STRUCTURE BAPIADSMTP OPTIONAL
*" ADDRML STRUCTURE BAPIADRML OPTIONAL
*" ADDX400 STRUCTURE BAPIADX400 OPTIONAL
*" ADDRFC STRUCTURE BAPIADRFC OPTIONAL
*" ADDPRT STRUCTURE BAPIADPRT OPTIONAL
*" ADDSSF STRUCTURE BAPIADSSF OPTIONAL
*" ADDURI STRUCTURE BAPIADURI OPTIONAL
*" ADDPAG STRUCTURE BAPIADPAG OPTIONAL
*" ADDCOMREM STRUCTURE BAPICOMREM OPTIONAL
*" GROUPS STRUCTURE BAPIGROUPS OPTIONAL
Ive Managed to glean from various sources on the internet, the various basics on doing a bapi call from VBA
Here is what i have so far.
Private Sub Fetch_User_details_Click()
'Take username in cell 2,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Variant
Dim Preturn As Variant
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 200
For y = 1 To 8
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = ""
R3.Connection.client = ""
R3.Connection.user = ""
R3.Connection.Password = ""
R3.Connection.Language = "EN"
'Logon to SAP
If R3.Connection.logon(0, False) <> True Then
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
copyFromc = Worksheets("Sheet1").Cells(3, 2).Text
Set Pusername = MyFunc.exports("USERNAME")
Pusername.Value = copyFromc
'Call the BAPI
If MyFunc.call Then
' ok now what ?
' Process the returned data into the spreadsheet
Else
MsgBox ("Call returned FALSE")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
To update the data ( User Role Assignements ) i will be using bapi BAPI_USER_ACTGROUPS_ASSIGN
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" TABLES
*" ACTIVITYGROUPS STRUCTURE BAPIAGR
*" RETURN STRUCTURE BAPIRET2
* Dieser Baustein ist gleichgestellt mit der Pflege eines Benutzers
* über die Pflegetransaktion, gepflegt werden die Felder, für die die
* Pflege erlaubt ist
I need help deciphering the data received from the bapi and then repackaging it using VBA.
I know writing this in ABAP would take less than 30 mins, but that is not an option for me.Ok, Ive made some headway
I can now Read all the data i need from SAP
Now comes the bit to write it back again. Will Update when i have a solution
Private Sub copydata_Click()
Dim x1 As Integer, x2 As Integer
'copy all data from "Copy From" to "Copy To"
'first determine how many rows contain roles
'before copying the roles, check that the destination user has no roles assigned
If Cells(9, 6).Text <> "" Then
MsgBox ("Error. Destination User already has Roles assigned.")
Exit Sub
End If
For x1 = 0 To 1000
If Cells(9 + x1, 1).Text = "" Then
Exit For
End If
Next
Worksheets("Sheet1").Range(Cells(9, 1), Cells(9 + x1 - 1, 4)).Copy _
Destination:=Worksheets("Sheet1").Range(Cells(9, 6), Cells(9 + x1, 9))
For x2 = 1 To x1
Worksheets("Sheet1").Cells(9 + x2 - 1, 8).Value = Date
Next
End Sub
Sub Mail_small_Text_Outlook()
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "User " & Worksheets("Sheet1").Cells(3, 7).Text & _
" Has Been Moddelled off of User " & _
Worksheets("Sheet1").Cells(3, 2).Text & " in system " & _
Worksheets("Connection").Cells(1, 2).Text & vbNewLine & vbNewLine & _
"Please Adjust Mitigating Controls Accordingly"
On Error Resume Next
With OutMail
.To = Worksheets("Connection").Cells(10, 2).Text
.CC = ""
.BCC = ""
.Subject = "User Modelled"
.Body = strbody
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Private Sub Fetch_CopyTo_User_Click()
'Take username in cell 3,7 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Cells(5, 8).ClearContents
Worksheets("Sheet1").Cells(6, 8).ClearContents
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 7).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 7).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 7).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 6).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 7).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 8).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 9).Value = datarec("TO_DAT")
x = x + 1
Next
copydata.Enabled = True
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub Fetch_User_details_Click()
'Take username in cell 3,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section and other areas of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 1000
For y = 1 To 9
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
Worksheets("Sheet1").Cells(5, 2).ClearContents
Worksheets("Sheet1").Cells(6, 2).ClearContents
Worksheets("Sheet1").Cells(5, 7).ClearContents
Worksheets("Sheet1").Cells(6, 7).ClearContents
copydata.Enabled = False
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 2).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 2).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 2).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 1).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 2).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 3).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 4).Value = datarec("TO_DAT")
x = x + 1
Next
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub UpdateSap_Click()
End Sub -
Call RFC enabled function from within VBA in BI 7.0
Hello Experts,
the problem that we have should be general, i have found some postings on this forum concerning it, but unfortunately no proper solutiont.
I just want to have the possibility to call the rfc enabled function module from within the callback function in VBA after executing of some query.
I have seen the suggestion to build a new RFC connection in VBA, but therefore you should hard-code all connection parameters (including user + password)
in the VBA code, this solution is for us not acceptable due to the security reasons.
Is there some way to use the existing connection of BEx Analyser in order to execute the function calls?
This functionality was possible in 3.5 but not in 7.0 since many functions that were available in 3.5 are not supported now.
Do you have experience/suggestions for this problem?
Any help would be great.
Thanks a lot,
KirillI've got the same problem. Did you find the solution?
Thank you,
Maybe you are looking for
-
I had a free trial of Adobe CC on my mac at home, which I since uninstalled . Later, I purchased on the PC I use at work with a Different email address than home. I have not been able to install at home. When I log in the email address is preprinte
-
Number of lines in a Field of type Text with Javascript
Hi, I have a form where I need to dynamically retrieve the number of lines in a Field of type Text. When I use getField(), I'm returned an object of type Field. I can see such properties as rect, but nothing concerning the number of lines of text in
-
Incorporating image purchasing with in my site.
Hey all I was just wanting ideas for being able to sell photographs on a iwebsite. Whether it is software that will do it for me, or more simple like showing the photos and leaving a email with the photo name. Any ideas would be great Trying for the
-
ADF: Error with API's OIM
Hi! i am work with view object programmatically, and ADF project with Business Component too. So when i run the (JSP & JSF) i have this error: 11/07/19 15:39:33 log4j:WARN No appenders could be found for logger (com.sun.faces.config.ConfigureListener
-
Edge Animate CC saving older version of my file
I've been working on a file in EA and I changed some of the imported images and saved the file . I made sure that the publish settings were correct. But when I try to Place the .oam file into a Muse CC project it always gives me the older version of