Using VBS with Portfolio (Basic steps)


<< Can I use VBA, VBScript o ...
Back to Portfolio FAQ index
The Portfolio VB Type Lib ... >>

[Tutorial courtesy of John Beardswoth]

Visual Basic Script (VBS) files can also be used to script Portfolio, interacting with catalogues in a similar way to Visual Basic (VB) executable or an Excel / Word VBA macro, and sharing most code with VB and VBA. However, VBS code:

This is a very simple VBS script which can be double-clicked in Windows Explorer. Windows recognizes the .vbs extension and shows a dialog box.


Visual Basic Script uses "late binding" to identify that it is interacting with Portfolio. This is unlike VB and VBA, where a Reference to Portfolio is added to the code project - a practice known as "early binding". Instead, we add a line of code at the start of the script:

Set PortObj = CreateObject("Portfolio.Document")

From this point, the code is often the same as VB or VBA. In this example, after the initial binding line, the code was actually copied directly from VBA.


Set PortObj = CreateObject("Portfolio.Document")
Set portRecord = PortObj.Gallery(1).SelectedRecords(1)
kvCount = CInt(portRecord.Field("Keywords").MVDataCount)
strValue = ""
For i = 1 To kvCount
  strValue = strValue & portRecord.Field("Keywords").GetMVData(i) & vbCrLF
Next
mykeywords = InputBox(strValue, "Keywords", strValue)
Set PortObj = nothing

When a record is selected in the Portfolio client, double-clicking the vbs file will produce a dialog box listing the record's keywords. They are separated by line breaks and can be copied and pasted into another application.

Usually scripts are launched by placing the executable files in Portfolio's Scripts folder. When the Portfolio client is re-opened, the file names are added to Portfolio's Scripts menu and run when selected. However, Portfolio cannot launch a VBS file directly - while VBS files are added to the Scripts menu, they won't execute directly from the Portfolio interface. The workaround is that DOS batch files can be directly launched from Portfolio, just like exe files, and a batch file can trigger a VBS file:

Keywords (to assist indexing/searching):



Question: Using VBS with Portfolio (Basic steps) [FAQ00366.htm]
Last Update:- 01 June 2006


<< Can I use VBA, VBScript o ...
Back to Portfolio FAQ index
The Portfolio VB Type Lib ... >>

Quick Search of PortfolioFAQ (word, words or phase): or try the Advanced Search

User-to-User Forums  |  Report error/typo/broken link  |  Request new topic  |  Ask a question

Site and articles © Mark Anderson 2001-2007 - Visit my home page


This FAQ is created and maintained using
Friday logo
Friday - The Automatic FAQ Maker