vbs scripting and export to excel file

By Pommyboy_FearFactory ·
Hi there,

kinda a scripting newbie, i would like a script to pull information from another txt file on a server that gets updated every 2 mins...

what i want to do is have a script that pulls information about what time a specific list of users and what time the logged on (this is all in the txt file).
and then export the information into a .xls file to view.

i dont know the first thing about scripting, could you point me to some links about vbs scripting.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Well there is a lot of information on w3schools

by Slayer_ In reply to vbs scripting and export ...

What is going to run your script? You said the source updates every 2 minutes, so what will run your script every 2 minutes? Or do you just intend to run it manually.

Because it may be easier to just right a Macro in the excel spreadsheet that will read the source file, and output the data. This would be far easier than using a VBScript to do it. (Which would require FileSystemObject's and Excel objects, worksheet objects, ick ick ick)

Just stick a button on an excel document and on its click event, parse that file of yours and output the results. Basic Excel macros are super easy.

Excel uses a langage called VBA, which is a dumbed down version of VB6 (And VBScript is a dumbed down version of VBA, so be afraid)

I would be able to help more if I knew what format your source data is in.

I will just make up some fake code for you here

Say my source is this


My VBA code would look something like this

private sub command1_click()
dim sUsers() as string
dim sUserLine as string
dim i as integer
Open "C:\InputFile.txt" for input as #1
Line Input #1, sUserLine
Close #1


'I forget how to access cells
for i=lbound(sUsers) to ubound(sUsers) step 1
cell(1,i)=sUsers(i) 'fill first column with list of users
Next i
End Sub

Collapse -

Well... it's all perfectly possible

by neilb@uk In reply to vbs scripting and export ...

Personally, if I were doing it now and was going to learn a bit about scripting, I'd use PowerShell which is MS's replacement for vbscript and is their Sysadmin management tool of choice for the future.

Here's a bit of code that creates a spreadsheet, writes a couple of values and saves it. See if you think that you're up for it - I don't see why not - and then Google because there are shed-loads of bits of code out there.

$excel = New-Object -comobject Excel.Application
$workbook = $excel.Workbooks.Add()
$sheet = $workbook.Worksheets.Item(1)
$sheet.Cells.Item(1,1) = "A value in cell A1."
$sheet.Cells.Item(1,2) = "Another value."

Neil :)

p.s. If you're using XP or Server 2003, because you aren't from the US, make sure you get PowerShell 2.0 as the Excel stuff never worked in earlier versions.

Knuckle-marks all over my screen...

Related Discussions

Related Forums