Export data from listview to OpenOffice VB6 - vb6

I have a program that displays data from a CSV file into a ListView.
I then have a button called "Reports" - when I click this I want the data to be displayed from the ListView/CSV file in OpenOffice Calc.
This is my code:
Private Sub cmdReports_Click()
Dim oSM As Object
Dim oDesk As Object
Dim oDoc As Object
Dim oSheet As Object
Dim i As Integer
'Instanciate OOo : this line is mandatory with VB for OOo API
Set oSM = CreateObject("com.sun.star.ServiceManage…
'Create the first and most important service
Set oDesk = oSM.CreateInstance("com.sun.star.frame.D…
'Create a new doc
Set oDoc = oDesk.loadComponentFromURL("private:fact… "_blank", _
0, arg())
'Get the first sheet in the doc
Set oSheet = oDoc.getSheets().getByIndex(0)
With oSheet
For i = 1 To ListView1.ListItems.Count
.cells(i, 1) = ListView1.ListItems(i).Text
.cells(i, 2) = ListView1.ListItems(i).SubItems(1)
.cells(i, 3) = ListView1.ListItems(i).SubItems(2)
.cells(i, 4) = ListView1.ListItems(i).SubItems(3)
Next
End With
End Sub
At the moment all my button is doing giving me Run-time error '438' Object does not support this property or method
When I debug this line is highlighted:
.cells(i, 1) = ListView1.ListItems(i).Text
This code was written for Excel but I edited it so it can be displayed in OpenOffice Calc.
Can anyone help please?
Thanks

It means exactly what it says - the statement is using a property of method that isn't supported by the Ole Automation interface. First question: can you use a type library (see the References dialogue - is there something like OpenOffice Calc in the list)? Knowing what methods and properties are available at compile time is much better - you can do the same with Microsoft Excel. Then you could declare your variables as a specific type, rather than "As Object".
Not knowing OpenOffice, I looked for documentation on OpenOffice, and found the next best thing, Star Office. Try: http://www.openoffice.org/api/basic/man/tutorial/tutorial.pdf . Look at page 64, section 4.4 for documentation on the spreadsheets. The object model looks different to Office, which would explain your problem.
It looks as if you need to use the Sheet.getCellByPosition() method, rather than the Cells() method, e.g.
GetCell = oSheet.getCellByPosition (nColumn , nRow)

Related

HP UFT/QTP 14.00, import CSV and maintain the values in data sheet

i'm importing some data from a csv file, here is the data:
*file.csv
UserName, EmailId, PhoneNumber
Antonio, anto#gmail.com, 1234567890
Oscar, osc#yahoo.com, 9999999999
Luis,lu#hotmail.com,8888888
I have a Function to call this file:
'************************************************************
Function ImportCsvFiletoDatatable(CsvFilePath,SheetName,HeaderDelimiter)
Dim filePath
Dim fso
Dim f
Dim fData
Dim arrData
Dim CsvValue
Dim CsvSheet
Dim CsvFirstLine
Dim CsvColumns
Dim ColumnIndex
Dim rIndex
Dim cIndex
filePath=CsvFilePath 'Specify file Path
'Open CSV File using File System Object
Set fso=createobject("scripting.filesystemobject")
Set f = fso.OpenTextFile(filePath)
CsvFirstLine=f.readline 'Treating like first line is the column names
CsvColumns=split(CsvFirstLine,HeaderDelimiter) 'Split the line using HeaderDelimiter
Set CsvSheet=DataTable.GetSheet(SheetName) 'Get the Specified sheet
'Add the splitted values as Datatable Columns
For ColumnIndex=lbound(CsvColumns) to ubound(CsvColumns)
CsvSheet.addparameter CsvColumns(ColumnIndex),""
Next
While not f.AtEndOfStream
rIndex=f.Line-1 'Specify Row index
fData=f.ReadLine ' Read CSV File Line
arrData=split(fData,",") 'Split the line
cIndex=1 'Specify Column Index
CsvSheet.SetCurrentRow(rIndex) 'Set Row in the Datatable
' Add values in Datatable
For Each CsvValue In arrData
CsvSheet.getparameter(cIndex).value=CsvValue
cIndex=cIndex+1
Next
Wend
f.Close
Set fso=Nothing
End Function
'************************************************************
And works well, but the information is volatile, and i can't manage, or use the data.
Someone know how to keep the data in the data sheet, although leave UFT?
Dim objQtApp, strXlsPath
strXlsPath = Environment("TestDir") & "\Default.xls"
Set objQtApp = CreateObject("QuickTest.Application")
DataTable.Export strXlsPath
objQtApp.Test.DataTable.Import strXlsPath
Set objQtApp = Nothing
The Design Time DataTable is found in the Default.xls. This is loaded when you open a test case or if you edit it manually from UFT. In case you want to refresh it programmatically use the code-snippet above. Export and then with AUtomation Object Import.
Of course put it into a method and call from whatever place is convenient for you.
If you want UFT to take care of it automatically, Create a new Class and a singleton Instance of it.
Implement the Class_Terminate method of the class and put the code there. WHenever UFT exits either because of a crash or or a nomral test run ends, it will try to clean up all Objects created while running. This object will be among them, and as a part of the automatic cleanup process you will save your runtime datatable into the design-time one(Default.xls) and then reload it.

Assign Attachment Field To Variable in Access 2010

I'm trying to understand how to work with the new Attachment field that is available in Access 2010. I would like to assign the value from the table directly into a variable. I know that I can do this if I use an intermediary form, but this seems like sloppy coding to rely on a form in order to grab a value from a table. Is there some way to grab what is in an attachment field and assign it directly to a variable? I have multiple instances where this would be handy for me. The first instance is I want to grab a photo stored in an attachment field to assign to the ribbon. A second instance is to load a company logo from a table into a variable and keep it in memory to use throughout the program as needed.
The code I have so far is this, but it gives me a type mismatch error:
Dim ParentRS As Recordset, ChildRS As Recordset, Img As Attachment
Set ParentRS = CurrentDb.OpenRecordset("SELECT * FROM LtblImg;", dbOpenSnapshot)
If ParentRS.RecordCount > 0 Then
Set ChildRS = ParentRS("Img").Value
If ChildRS.RecordCount > 0 Then
Set Img = ChildRS("FileData")
End If
ChildRS.Close
End If
ParentRS.Close
Yes, Dim Img As Attachment looks tempting, but Attachment (which is actually Access.Attachment) refers to an Attachment control that could be used on a form (just like Access.TextBox) and does not appear to be suitable for your intended purpose.
The only native VBA type for storing this sort of binary data is an array of Byte values, but often when dealing with byte arrays we wind up looping through and processing them byte-by-byte, which is tedious and inefficient.
You might consider using a binary ADODB.Stream object as your "variable". You could create a function to retrieve the attachment bytes and return them in a Stream like so
Option Compare Database
Option Explicit
Public Function GetLogoAsStream() As ADODB.Stream
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, fldAttach As DAO.Field2
' Project references required for early binding:
' Windows Script Host Object Model
' Microsoft ActiveX Data Objects 2.8 Library
Dim fso As FileSystemObject, tempFileSpec As String
Static strm As ADODB.Stream
If strm Is Nothing Then
Set fso = New FileSystemObject
tempFileSpec = fso.GetSpecialFolder(TemporaryFolder) & "\" & fso.GetTempName
Set fso = Nothing
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset( _
"SELECT [AttachmentFiles] " & _
"FROM [AttachmentsTable] " & _
"WHERE [Description]='SO logo'", _
dbOpenSnapshot)
Set rstAttach = rstMain("AttachmentFiles").Value
' make sure we use the correct file extension
tempFileSpec = tempFileSpec & "." & rstAttach.Fields("FileType").Value
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.SaveToFile tempFileSpec
Set fldAttach = Nothing
rstAttach.Close
Set rstAttach = Nothing
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing
Set strm = New ADODB.Stream
strm.Type = adTypeBinary
strm.Open
strm.LoadFromFile tempFileSpec
Kill tempFileSpec
End If
strm.Position = 0
Set GetLogoAsStream = strm
End Function
and then if you had, say, a Report like this with an empty Image control
and an On Load event procedure like this to load the Image control's .PictureData from your "variable" (actually a Function returning an ADODB.Stream)
Private Sub Report_Load()
Me.LogoImage.PictureData = GetLogoAsStream.Read
End Sub
it could produce something like this

How to read and write non-standard document properties of word file in vbscript?

Microsoft Word is offering some default document properties to be set in Word documents.
There is a number of default properties, for which vbscript has constants.
But Word (2011) is offering some more properties, e.g. companyfaxnumber, publishingdate,keywords.
There is a possibility to access the builtin properties by calling
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open(strFilePath)
For Each prop In oWord.ActiveDocument.BuiltInDocumentProperties
WScript.Echo prop.Name + "::" + oWord.ActiveDocument.BuiltInDocumentProperties(prop.Name).Value
Next
But how do i find the names of the "custom" properties that are offered by word, but are not present in vbscript as constant?
There is the function
Document.CustomDocumentProperties
But if i do a listing like the one above, i get properties named info1, info2, etc.
Too access the Word CustomDocumentProperties, you will need to be able to access the OLE File Property Reader. This expands beyond the normal/simple document properties because it allows you too add custom properties as well.
There is a Tales from the Script article from 2005 detailing the installation and usage of utilizing CustomDocumentProperties within Word -> Here
For the download to install the OLE Property Reader DLL, Go -> Here
Here is an example of property set/get once the property read is installed:
Const msoPropertyTypeBoolean = 2
Set objFile = CreateObject("DSOFile.OleDocumentProperties")
objFile.Open("C:\Scripts\New_users.xls")
'Set
'=======================================================================
objFile.CustomProperties.Add "Document Reviewed", msoPropertyTypeBoolean
objFile.Save
'Get
'=======================================================================
Set objProperty = objFile.CustomProperties.Item("Document Reviewed")
wscript.echo objProperty.Value
Enjoy!
Hi recently figured out how to get there myself:
The Word "Frontend Editor" is cheating on the document properties. There is a hard defined set of properties like author,category, keywords etc.
The additional properties offered by the editor are so called custom properties which are defined in an external XML structure inside the docx-container.
So there is no easy vbscript function to modify the values of these custom properties.
Thanks to the web, someone did some hacking and this is the solution for it:
Sub WriteCustomCoverProperties(ByRef wordInstance, strProp, strText)
Dim oCustPart
Dim oNode
Dim strXPath
strProp = Replace(strProp, " ", "")
Select Case strProp
Case "Abstract" strXPath = "/ns0:CoverPageProperties[1]/ns0:Abstract[1]"
Case "PublishDate" strXPath = "/ns0:CoverPageProperties[1]/ns0:PublishDate[1]"
Case "CompanyAddress" strXPath = "/ns0:CoverPageProperties[1]/ns0:CompanyAddress[1]"
Case "CompanyPhone" strXPath = "/ns0:CoverPageProperties[1]/ns0:CompanyPhone[1]"
Case "CompanyFax" strXPath = "/ns0:CoverPageProperties[1]/ns0:CompanyFax[1]"
Case "CompanyEmail" strXPath = "/ns0:CoverPageProperties[1]/ns0:CompanyEmail[1]"
Case Else
Exit Sub
End Select
Set oCustPart = wordInstance.ActiveDocument.CustomXMLParts(3)
Set oNode = oCustPart.SelectSingleNode(strXPath)
oNode.Text = strText
Set oCustPart = Nothing
Set oNode = Nothing
End Sub
May it be of help =)

Run time error 1004, Application defined or object defined error in excel vbs

I have written vbscript code to add chart in page 1 of excel for which the source is from other sheet of same excel which name is "CL.1.1" but i am getting the above error can any one help what was wrong in my below code.
Sub DispvsTime(Shname)
Sheets("Sheet1").Select
noofsheets = ActiveSheet.ChartObjects.Count
If noofsheets > 0 Then
ActiveSheet.ChartObjects.Select
ActiveSheet.ChartObjects.Delete
End If
Sheets("Sheet1").Pictures.Visible = False
ActiveSheet.Shapes.AddChart(1000, 420, 50, 500).Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Sheets(Shname).Range("G2:H2001")
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = "Displacement VS Time"
End Sub
here shname is name of the sheet where data is picked.
Can any one help me to find out the bug inside the code to get this error ?
If the sheet name is Shname then place it around quotation marks, if it is a variable name, which holds the sheet name, then ignore this post :P
Sheets("Shname")
If your code is really VBScript as you say, and not VBA as it looks like, then there are several issues:
Unlike VBA you cannot use objects like ActiveSheet or ActiveChart directly in VBScript. You need a reference to these objects, usually the application object:
Set xl = CreateObject("Excel.Application")
xl.ActiveSheet.Name = "foo"
VBScript doesn't know about Excel/Office constants like xlXYScatterSmoothNoMarkers or msoElementChartTitleAboveChart, so you have to either use literal values or define those constants yourself:
Const xlXYScatterSmoothNoMarkers = 73
You can't use named arguments like Source:=... in VBScript:
xl.ActiveChart.SetSourceData xl.Sheets(Shname).Range("G2:H2001")
See here for a more detailed explanation of the differences between VBA and VBScript.

ArcPad - VBscript - Autopopulate attributes

I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.
There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function. No matter where I place a point it gives the same parcel # and address. Or maybe it isn’t actually be performing the IF function properly.
Sub Address
Dim rsCurrentXY
Set rsCurrentXY = Map.Layers("Violations").records
rsCurrentXY.movelast
Dim objXYShape
Set objXYShape = rsCurrentXY.Fields.Shape
Dim pControls
Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(“PAGE1”).Controls
Dim rsGrid
' Find corresponding map page to the valve point
Set rsGrid = Map.Layers("ACPA_parcels").records
rsGrid.movefirst
Do While Not rsGrid.eof
If rsGrid.fields.shape.Ispointin(objXYShape) Then
pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
Exit Do
End If
rsGrid.Movenext
Loop
' Clean Up
Set rsCurrentXY = Nothing
Set objXYShape = Nothing
Set rsGrid = Nothing
End Sub
(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.
Thanks for the help,
Robert
Accessing the EDITFORM via Application.Map.selectionlayer.Forms("EDITFORM") will be problematic. Whenever working with controls on an EDITFORM you should using ThisEvent.Object to discover all your objects. For example, if your event handler is Page_OnLoad then ThisEvent.Object will refer to your current page. You should have code like this:
Dim pPage1
Set pPage1 = ThisEvent.Object
Dim pControls
Set pControls = pPage1.Controls

Resources