VBA Object Model reference documentation - excel

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.

Related

Hide Data Field in an Org Chart in all Shapes in Visio Using VBA

I have code that runs and imports a lot of data from Excel to Visio, adds fields, formats, etc. It all works fine but recently we decided we want to be able to hide one of the fields (the top/first field) as an option. I have tried to record a macro to record the steps of going to the Org Chart tab, then shapes, then to fields, and de-selecting the item in Block 2, which works. However, that does not seem to actually do anything when I then try to use that recorded code.
Does anyone know how to use a macro to select/hide specific data fields in a Visio Org Chart? Again, we can do it manually, but I am trying to incorporate it as an option in the larger import macro.
As far as I know, the OrgChart Visio feature does not provide any API to interact with, i.e. does not expose any extensibility options for third-party developers to use.
From what I could imagine, you could try to modify the OrgChart's settings directly in the Visio file, either in the VSDX file itself, or using document.SolutionXmlElement to access its settings. The settings themselves look somewhat like this:
<SolutionXML Name="SolutionModel">
<SolutionModel xmlns="http://schemas.microsoft.com/visio/2003/solutiondata">
....
<mstns:Root ID="{....}">
<mstns:Block1CustomProperty>Name,Title,Department</mstns:Block1CustomProperty>
<mstns:Block2CustomProperty>None</mstns:Block2CustomProperty>
<mstns:Block3CustomProperty>None</mstns:Block3CustomProperty>
<mstns:Block4CustomProperty>None</mstns:Block4CustomProperty>
<mstns:Block5CustomProperty>None</mstns:Block5CustomProperty>
I would have given up, though.
Another way to interact with the addon is to use SendKeys to simulate key presses.
Here is a link to some example code:
SendKeys example

Integrate VBA - SAP with Outlook [duplicate]

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:

Blueprism Excel VBO issue

When i try to use Excel VBO-open workbook in blue-prism,it says:Internal :Unable to execute code link because the code link throws an exception:The target of the call has an exception.
Then I tried MS Word VBO to read a newly created doc file, but the same problem.
My step is create instance, open workbook .
This xlsx file can be load in other software like uipath.
Probably Blue Prism use comma separator style based on installation location even if windows default language is english.
For me installing MS Office Language Accessory Pack for Office(with my native Polish) helps. It changed the comma separator from ' . ' to ' , '
Check also Control panel(Win 7)/Clock, language and Region/Change location/Formats/Additional settings/Decimal symbols
More information is required, as the internal exception that you're getting could be caused by ANY number of issues, brought on by either user, Blue Prism, Excel, or the resource/environment.
This has more to do with the poor construction of the Blue Prism Excel VBO than anything.
One piece of advice though: don't use the 'Create Instance' action, ever. Try simply using the 'Open Workbook' action by itself, as if there is not current instance open or identified it will create one anyway and pass out the Instance Handle for use.

Store information of workbook and add-in

There is an Excel add-in that allow users to make comments (not the traditional comments provided by Excel) for spreadsheet cells. The add-in memorizes all the cells that have comments in a workbook.
I am wondering where these information are actually stored. Are they stored in some hidden part of the workbook? Are they stored in the server of the add-in, then how are workbooks identified?
If you're referring to an add-in that somehow "remembers" a particular Range across document open/close sessions (e.g., how the Bing Maps add-in does it), it's using Bindings beneath the covers. Bindings -- which are conceptually a lot like the user-facing Named Ranges, but are invisible and are per add-in (so no name collision risk) -- are stored in the document, just like named ranges.
As Kim points out, this is often combined with Settings to create an add-in that both binds to some ranges (with a GUID-like name, for example), and stores some metadata keyed off of the binding name.
On a side note, if you want to reference ranges only for a specific duration of time while the add-in is running but you don't need these to persist in the document, you can instead use object-tracking. It is described in great detail in the book "Building Office Add-ins using Office.js", (disclaimer: I am author of said book), in a chapter called "Using objects outside the 'linear' Excel.run or Word.run flow (e.g., in a button-click callback,in a setInterval, etc.)".
Using the Office.js API, you can use the Settings object (Office.context.document.settings) to store name/value pairs in the host document. For details about how this works, see the documentation here: https://dev.office.com/reference/add-ins/shared/settings.
As the documentation indicates, the settings that you create/save using the Settings object are saved per add-in and per document, which matches the scenario that you've described. Regarding where settings data actually gets stored, check out the answer on this other Stack Overflow post -- which describes how/where settings data is persisted for a host document. (Note: I haven't personally verified that answer, so I'd suggest that you do some testing to verify/confirm its accuracy for your scenario.)

Can I access and query web-based Crystal Report Viewer through Excel VBA?

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.

Resources