Is there a way to view the properties on SAP GUI objects?
Like this:
But for SAP objects like the following ones:
Set SAPGuiAuto = GetObject("SAPGUI")
Set App = SAPGuiAuto.GetScriptingEngine
Set Connection = App.Children(0)
Set SAPSession = Connection.Children(0)
I ask this after reading the last part of the answer to this post: VBA general way for pulling data out of SAP
If however you want to use early binding so that your VBA editor might
show the properties and methods of the objects you are using, you need
to add a reference to sapfewse.ocx in the SAP GUI installation folder.
This is something so badly advertise by the SAP team, they should definitely do a better job there.
Basically you first of all need to add a reference to the SAP object model, the libraries that VBA will understand. Don't know how familiar are you with there references to object models. Basically, on your VBA Editor, click Tools, then References, then Browse, and find this file: "C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx" (or possibly "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewse.ocx").
Now you'll be able to browse it on the Object Explorer (press F2 in the VBE), and declare the types.
You need now to familiarise yourself with the Types of this library. Some hints, they all start with Gui, like, GuiSession, GuiApplication, GuiConnection, GuiBlabla... Names are pretty explicit and intuitive.
To add on to what #Nelson_Vides has said. As he said, you will need to reference the sapfewse.ocx file, and you can view the class objects by pressing F2.
However, the IntelliSense will only be visible once you define an object from the SAP class library.
Dim userArea As GuiUserArea ' <-- For example
Now, whenever the object is used the IntelliSense will show up.
Best of luck and happy scripting!
SAP also provides documentation on their GUI objects:
Related
I'm unable to create any objects in an Excel macro I am trying to write. Initially I was trying to work with MSXML2.DOMDocument60, however, I realized that i'm not able to get ActiveX to create any objects. For example, I get the same error (Run-time 429 'ActiveX component can't create object') for this line of code:
Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")
Obviously since i'm in excel, the program is installed correctly and it should have access to it. I've checked several other Stackoverflow pages for this. It doesn't appear to be an issue with a reference and I can't imagine the simple code above not working because of missing dlls since I am again already in Excel.
Is there possibly a security feature on my computer blocking this action?
Again, my issue is not with the above code. This was just a simple way to show that Create object is not working.
My main goal is to get the following to work:
Dim objXML As MSXML2.DOMDocument60
Set objXML = CreateObject("MSXML2.DOMDocument60")
I've already verified that I have the correct reference and I re-registered the Dlls.
I found the answer I was looking for. My company has the C drive and another network drive locked down, which prevents CreateObject from working when an excel sheet is saved to either of these locations. By saving the excel sheet to my desktop instead I am able to get it to work.
There's no class with an Excel.Sheet progID in the Excel object model. You probably meant Excel.Worksheet, but that won't work either, and it's not because of CreateObject or any kind of obscure security feature.
Simply put, not all classes/types are creatable: In the Excel type library Application is, and that's about it: everything else needs to be created within the object model, using the factory methods provided by that API.
In other words the only way you can create an Excel.Worksheet, is if Excel creates it for you.
Set excelSheet = Excel.Application.ActiveWorkbook.Worksheets.Add
Same with an Excel.Workbook:
Set excelBook = Excel.Application.Workbooks.Add
There are other ways (e.g. copying an existing Worksheet without specifying a Target argument will create a new Workbook that contains a copy of that source Worksheet), but rule of thumb if you can't New up a class in a referenced type library, there's little chance CreateObject can do any better (unless the type registration explicitly prevents early-binding usage).
The question was edited, but this answer stands: don't use CreateObject to create instances of classes that are already resolved and readily available.
Set objXml = New MSXML2.DOMDocument60 'works fine
If you really want to use CreateObject, then you need to use progID strings that exist in your registry.
Set objXml = CreateObject("MSXML2.DOMDocument60") ' blows up on my machine as well
Set objXml = CreateObject("MSXML2.DOMDocument") ' works fine
But using CreateObject to create an instance of a class the compiler already knows about, is a very, very roundabout way to do this.
I'm a trainee and my boss asked me to make a script that searches for packages in Enterprise Architect from a name. The base is in Excel and count all the use-cases, the count I already did, but the search I could not get yet.
*edit: the count im already made, but i need a search metod, get all names from a excel file and searchs this names on Ea
You can do this with the ActiveX Object functionality with Jscript in EA, basicaly you can open the excel sheet directly from your script and read the data
ActiveX Object Jscript Reference
ActiveXObject in Sparx EA
VBScript, JScript and Javascript can each create and work with ActiveX
/ COM objects. This can help you to work with external libraries, or
to interact with other applications external to Enterprise Architect.
For example, the Scripting.FileSystemObject Class can be used to read
and write files on the local machine. The syntax for creating a new
object varies slightly for each language, as illustrated by these
examples:
VBScript:
set fsObject = CreateObject("Scripting.FileSystemObject")
JScript:
fsObject = new ActiveXObject("Scripting.FileSystemObject");
Javascript:
fsObject = new COMObject("Scripting.FileSystemObject");
Note: from my personal experience, this doesn't work with a JavaScript script, use Jscript or VBscript
Is there a place where I can simply find the Object Model hierarchy and kind of API for VBA for Excel 2013?
I am looking at MSDN URL
http://msdn.microsoft.com/en-us/library/office/ff841127(v=office.15).aspx
But that seems confusing.
Example:
If I am writing
Selection.Interior.ColorIndex = -4142
I would like to have an API (online or offline) to understand the Object Models starting with Selection and work (and explore) my way to ColorIndex. By reading the associated documentation as well.
The only way I think that's possible is by having a structured document like Java Docs.
Any references/tips will help.
System Info:
MS Excel 2013
VBA
Windows 8, 64 bit
UPDATE:
While searching for answers, I got the below image from http://msdn.microsoft.com/en-us/library/aa141044.aspx
Update:
Based on entry by user Oliver below:
My office help doesn't seem to be working.
Generally, if a variable or other identifier can be resolved to a specific type, then Intellisense will show you the members of that type. For example:
Application.
will bring up a list of members.
Selection is a special case because although the currently selected item is often a range of cells, it could be something else as well - part of a chart sheet for example.
You can discover the underlying type of the object which Selection refers to, by adding a watch (Debug -> Add Watch...). Type Selection in the Expression box, and set the context to (All Procedures) and (All Modules) if it's not set that way already.
In the Watches window, you will see the actual type of the object referred to by Selection, and you can expand the + to see its properties. If the type says Object/Range, (meaning the type of the expression is Object and the type of the object referred to by the expression is Range), one of the properties will be Interior. If you look at the type column for Interior, you'll see Interior/Interior, because the type of the Interior property is indeed the Interior type.
If you type the following in code:
ActiveCell.
Intellisense will show you a list of members, including the Interior property, because the type of the ActiveCell property is the Range type.
Some other powerful tools for investigating the object model:
The Object Browser (View -> Object Browser) shows you a list of types available to your project, based on the libraries which the project references (can be viewed/changed at Tools -> References...). When a type is selected, you will see a list of members for that type. You can filter the types by library and/or by name. Members in the <globals> type can be used without any object references -- Interior needs some Range object to be used, but Selection can be used by itself.
The Immediate window (View -> Immediate window) lets you evaluate expressions (preface with a ? -- e.g. ?ActiveWorkbook.Sheets.Count) and run code in place (such as ActiveWorkbook.Save)
The Excel Developer reference is most probably right on your computer, it's just difficult to find:
Manual way:
Start Excel
Hit Alt-F11 to enter VBA Editor
On the Menu Bar, choose "?"->Microsoft Visual Basic Help
Now you are looking at the Excel-VBA Help and you can even search it in the top left box for "Selection".
Direct Link:
"C:\Program Files (x86)\Microsoft Office\Office15\CLVIEW.EXE" "EXCEL.DEV" "Microsoft Office Excel"
(At least this worked for Office 2007, i assume it does for 2013 as well)
Do you mean, while coding you would like to see function/sub explanations like JavaDoc?
Unfortunately this is not standard in VBA.
However you might want to take a look into this
Is there a good VB6 documentation system similar to Javadoc?
Another way to "see" the underlying Object Model called by Excel is to use the macro recorder.
Open the excel sheet and the VBA environment (ALT+F11) side by side.
Goto Developer tab and click "Record Macro".
From the VBE open the module1 from project explorer (this is where exlce writes macro by default).
Now make changes in your worksheet and see what code Excel is writing.
I download reports through web-based access to a Crystal Report Viewer. (Admittedly, my first problem is that I am not at all proficient with Crystal.) I generally have success using Excel VBA in automating IE navigation and HTML form manipulation, but I've run into a wall with this Crystal Report Viewer.
As an example, I can download a report through the Crystal Report Viewer by specifying for which of the fifty states I want the report. I am trying to automate it so that it will export all fifty reports at once (or, rather, in succession while I, say, go to lunch).
I've pulled the outerHTML of the site in question. It includes an OBJECT tag at the beginning containing 23 PARAM NAME tags followed by the following VBScript:
Sub window_onLoad()
Page_Initialize()
End Sub
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBroker.WebReportBroker")
If err.number <> 0 then
window.alert "The Crystal ActiveX Viewer is unable to create resource objects."
CRViewer.ReportName = "[a URL...redacted]"
Else
Dim webSource0
Set webSource0 = CreateObject("WebReportSource.WebReportSource")
webSource0.ReportSource = webBroker
webSource0.URL = "[a URL...redacted]"
webSource0.PromptOnRefresh = True
webSource0.AddParameter "password", "[somepassword]"
webSource0.AddParameter "user", "[someuser]"
CRViewer.ReportSource = webSource0
End if
CRViewer.ViewReport
End Sub
This script was followed by three more OBJECT tags, each making reference to codebases. I navigated to these references to find DLLs, which I would assume indicate the references I need to invoke in my VBA. On a hunch, I moved the VBScript into Excel VBA (is this dumb?) and placed it after my usual login and navigating code. I get a "Compile Error: Variable not defined" on the lines
window.alert "The Crystal ActiveX Viewer..." 'highlighting the word "window"
CRViewer.ReportName = "[a URL...redacted]" 'highlighting "CRViewer"
CRViewer.ReportSource = webSource0 'highlighting "CRViewer"
CRViewer.ViewReport 'highlighting "CRViewer"
This is where I run into problems. First, I may be going about this the wrong way, or it may not even be possible; but I wouldn't know. Second, if I am on the right track, there are A LOT of Crystal references listed in Excel VBA's available references. I have no idea which ones to use. BTW: the codebases make reference to
crviewer.dll
sviewhlp.dll
swebrs.dll
xqviewer.dll
cselexpt.ocx
crviewer.dep
crviewer.oca and
reportparameterdialog.dll
Any help would be appreciated. I realize I may not have provided all the necessary information here. Please let me know if more is needed. Thanks for reading.
Is the Web viewer part of a wider Business Objects setup, or something more basic that simply launches a viewer with the report?
If it's the former, you already have easier options for automating distribution via the web-based CMC, wherein report refreshes can be scheduled with a variety of distribution options, including to UNC paths.
If its the later, or for some reason the standard CMC/BO options aren't suitable, you might consider using a code library made for this purpose. The splinter library for Python is one such, and my preferred package for web automation: http://splinter.cobrateam.info/
If VBA is your coding comfort zone, there are a few ways of integrating python into VBA, all merely a google away... I won't detail them here since that's a sideline to this, and my answer is more of an alternative than a direct answer.
I'm trying to programatically import Microsoft.Office.Interop.Excel namespace into my vba project. I found this site
that displays how to import it manually, but I'm giving this project that I've been working on to people that won't know how to import it. Can anybody please help?
I assume from your question that your VBA code uses a reference to the Microsoft Excel 12.0 (or other version) library - and that your user gets an error as the reference cannot be found. In this case, you have two options:
Instead of referring to the v12 library, refer to an older library, e.g. from Excel 2003. To do so, search the net for this library and install it - or simply "relink" your file in an Office 2003 installation before shipping
Use late binding instead of early binding. In this case, you do not add a reference to the Excel library at all. Instead, you declare your objects as type Object(instead of Excel.Workbook, Excel.Application, etc.). To create a new object, instead of using Set objExcelApp = New Excel.Application, you must now use CreateObject (for new objects) or GetObject (for existing objects, e.g. an existing, running application): Set objExcelApp = CreateObject("Excel.Application"). Any later code will continue to work as usual (though it might be a tiny bit slower due to the late binding).
For further reading, check this answer.