Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrapping output in quote to distinquish from comma in field

Status
Not open for further replies.

tractng

MIS
Sep 26, 2005
21
US
Guys,

I need be able to tell the field that some of the data has a comma in it.

For example, the field Title. It may have something like VP, Finance. With the current code, it thinks it is a seperate field.

Below is my code.

-------------------------------------------------

'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem

'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")


Set OutPutFile = FileSystem.CreateTextFile("c:\email.csv", True)

Set oContainer=GetObject("LDAP://host1:389/OU=IT Dept,DC=test,DC=net")

'Enumerate Container
EnumerateUsers oContainer

'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing

WScript.Echo "Finished"
WScript.Quit(0)



Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"


If Not IsEmpty(oUser.sn) Then
OutPutFile.Write "," & "Last Name: " & oUser.sn
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.givenName) Then
OutPutFile.Write "," & "First Name: " & oUser.givenName
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.title) Then
OutPutFile.Write "," & "Title: " & oUser.Title
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.sAMAccountName) Then
OutPutFile.Write "," & "User ID: " & oUser.sAMAccountName
else
OutPutFile.Write ","
End If



If Not IsEmpty(oUser.department) Then
OutPutFile.Write "," & "Department: " & oUser.department
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.physicalDeliveryOfficeName) Then
OutPutFile.Write "," & "Building/Room: " & oUser.physicalDeliveryOfficeName
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.telephoneNumber) Then
OutPutFile.Write "," & "Phone: " & oUser.telephoneNumber
else
OutPutFile.Write ","
End If


If Not IsEmpty(oUser.mail) Then
OutPutFile.Write "," & "Email: " & oUser.mail
else
OutPutFile.Write ","
End If

OutPutFile.Write vbcrlf

Case "organizationalunit" , "container"

EnumerateUsers oUser
End Select

Next
End Sub
 


In notepad, it looks fine, but when I opened it up in excel (csv), the field are push back when the data has a comma in it.

Is that normal?

tnt
 
Use additional quotes perhaps ?
OutPutFile.Write ",""" & "Title: " & oUser.Title & """"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Thanks man. I will give it a try and will report back.
 
You could also use another character as a delimiter like vbTAB or even a semicolon.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top