OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

New to OO - Converting Word VBA to OO Basic, MS AD / LDAP

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Kiemo
Newbie
Newbie


Joined: 15 Mar 2005
Posts: 2

PostPosted: Tue Mar 15, 2005 3:10 am    Post subject: New to OO - Converting Word VBA to OO Basic, MS AD / LDAP Reply with quote

Hello,

I'm new to Open Office and am hoping to start using OO on our network and have a small question to ask that googling and searching here hasn't clearly answered for me.

Is it possible to programmatically access an LDAP connection

At the moment we have code similar to this:

Dim objAdSys, objUser, pth
Dim rngTarget, rngSource As Word.Range

Set objsys = CreateObject("ADSystemInfo")
Set objusers = GetObject("LDAP://" & objsys.UserName)

'Insert Users Personal Details
With ActiveDocument
.Bookmarks("StaffName").Range.Text = objusers.get("displayName")
.Bookmarks("SigStaffName").Range.Text = objusers.get("displayname")
.Bookmarks("Position").Range.Text = objusers.get("description")
.Bookmarks("Email").Range.Text = "Email: " & objusers.get("mail")
.Bookmarks("HEmail").Range.Text = "e: " & objusers.get("mail") & vbCr
.Bookmarks("DirectPhone").Range.Text = "Direct Phone: " & objusers.get("telephonenumber")
.Bookmarks("HDirectPhone").Range.Text = "d: " & objusers.get("telephonenumber") & vbCr
End With

'Insert users signature
Set rngTarget = ActiveDocument.Bookmarks("Signature").Range
rngTarget.InlineShapes.AddPicture "\\server01\Company\Signatures\" & objusers.get("displayname") & ".jpg"

Which basically populates areas of a document with the users details obtained from our AD such as email address, direct phone number etc.

I would also need to be able to programmatically insert an image file (signature).

Any help / comments / pointers to code and resources would be most appreciated.

Thanks In Advance

John
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Mar 16, 2005 2:32 pm    Post subject: Reply with quote

Hi, I have a free macro document with example code. I also wrote a book that explains macro programming in OOo.

I created the following example using the OOo 2.0 Beta, which should demonstrate how to connecto to an LDAP server. I do not have time at the momemnt to address your other questions. You might have better luck if you formulate each subtask separatly.
Code:
Sub ShowLDAPDriverArgs()
  Dim oManager   'Connection driver manager.
  Dim oDriver    'An indiviual driver.
  Dim oProps()   'Supported properties.
  Dim oProp      'A specific property.
  Dim s$         'Utility string variable.
  Dim i%         'Utility index variable.
  Dim sURL$
  Dim oCon
  Dim oParms(0) As New com.sun.star.beans.PropertyValue

  sURL = "sdbc:address:ldap:localhost"
  oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")

  REM Obtain a driver that supports the specified URL
  oDriver = oManager.getDriverByURL(sURL)
  If IsNull(oDriver) Then
    Print "Sorry, no driver available for " & sURL
    Exit Sub
  End If
  oProps() = oDriver.getPropertyInfo(sURL, ARRAY())
  For i = LBound(oProps()) To UBound(oProps())
    oProp = oProps(i)
    If NOT oProp.IsRequired Then
      s = s & "[" & oProp.Name & ", " & oProps(i).Value & ", " & _
                    oProps(i).Description & "]" & CHR$(10)
    Else
      s = s & "(" & oProp.Name & ", " & oProps(i).Value & ", " & _
                    oProps(i).Description & ")" & CHR$(10)
    End If
  Next
  MsgBox s, 0, "Properties for " & oDriver.getImplementationName()

  oParms(0).Name  = "BaseDN"
  oParms(0).Value = "OU=Users,O=Server"
  oCon = oManager.getConnectionWithInfo(sURL, oParms())
  Inspect(oCon)
  oCon.Close()
End Sub

_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Kiemo
Newbie
Newbie


Joined: 15 Mar 2005
Posts: 2

PostPosted: Thu Mar 17, 2005 1:19 am    Post subject: Thanks! Reply with quote

Thats enough to get me started and your book looks like it will tell me the rest. Thanks for the pointers!

John
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group