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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date stamp a vbs report

Status
Not open for further replies.

matrix101

MIS
Jun 5, 2007
60
US
howdy,

I have a vbs script which retrives data and brings it back into an excel spreadsheet. I need help figureing out how to date stamp it each time it runs.

any ideas would be great, thx!!!

 
in the filename..the app itself?...please elaborate
 
A starting point:
myTimeStamp = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes I would like it to be in the Excel application itself as part of the report. Below is the script I have so far, I would like to add a time stamp somewhere at the top of the report.

I just started learning so please explain if you have time, thanks I appreciate your guys help!

************

Const ADS_SCOPE_SUBTREE = 2
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add


objExcel.Cells(1, 1).Value = "Disabled Users Report"
objExcel.Cells(1, 1).Font.Bold = TRUE

Set objRange = objExcel.Range("A1","A1")
objRange.Font.Size = 12

objExcel.Cells(3, 1).Value = "User ID"
objExcel.Cells(3, 2).Value = "First Name"
objExcel.Cells(3, 3).Value = "Last Name"
objExcel.Cells(3, 4).Value = "Date Disabled"

objExcel.Cells(3, 1).Font.Bold = TRUE
objExcel.Cells(3, 2).Font.Bold = TRUE
objExcel.Cells(3, 3).Font.Bold = TRUE
objExcel.Cells(3, 4).Font.Bold = TRUE

Set objRange = objExcel.Range("A3","D3")
objRange.Font.Size = 11


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Const ADS_UF_ACCOUNTDISABLE = 2
objCommand.CommandText = _
"SELECT userAccountControl, SamAccountName, givenName, SN, ModifyTimeStamp FROM " _
& "'LDAP://dc=corp,dc=jitb, dc=net' WHERE " _
& "objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 4

Do Until objRecordSet.EOF
intUAC = objRecordset.Fields("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then

objExcel.Cells(x, 1).Value = _
objRecordSet.Fields("SamAccountName").Value
objExcel.Cells(x, 2).Value = _
objRecordSet.Fields("sn").Value
objExcel.Cells(x, 3).Value = _
objRecordSet.Fields("givenName").Value
objExcel.Cells(x, 4).Value = _
objRecordSet.Fields("ModifyTimeStamp").Value

x = x + 1

End If
objRecordSet.MoveNext
Loop

objRange.EntireColumn.Autofit()
 
add time function in the header

Code:
objExcel.Cells(1, 1).Value = "Disabled Users Report" & time
 
sorry...now function "timestamp"
Code:
objExcel.Cells(1, 1).Value = "Disabled Users Report " & now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top