Webmaster Forum

Go Back   Webmaster Forum > Scripting/Programming & Debugging > ASP & VBScript Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

ASP & VBScript Forum Need help from a webmaster with ASP or VBScript, you may ask in this forum?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-07-2007, 10:35 AM
heavydee heavydee is offline
Junior Member
 
Join Date: Sep 2007
Posts: 2
heavydee is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default text file to excel

Hello scripting gurus,

Who on earth can help me with a vbs code to copy 11 log (txt) files into excel

I have 11 text files that i need to read into excel everyday. This files are comma delimited, This i should be able to do with vbs without opening the text files one for one into excel.
All 11 text files has the same format and could all be placed in one worksheet in excel
Thanks in advance
Reply With Quote

This ad is part of our Revenue Sharing program
  #2 (permalink)  
Old 09-07-2007, 08:05 PM
ALL's Avatar
ALL ALL is offline
Senior Member
 
Join Date: Oct 2006
Location: Sturgis, SD
Posts: 145
ALL is on a distinguished road
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default

Try playing around with this:
HTML Code:
<script language="vbscript"> 'START CONFIG Dim strSaveLocation strSaveLocation = "fullpath\path_to_save_excel_document.xls" Dim aryFilesToOpen(2) 'You must change this number to however many files to open (remember to add 0 as one of them) aryFilesToOpen(0) = "fullpath_to_book\Book1.txt" aryFilesToOpen(1) = "fullpath_to_book\Book2.txt" aryFilesToOpen(2) = "fullpath_to_book\Book3.txt" 'END CONFIG 'Create Excel Object Set objExcel = CreateObject("Excel.Application") 'Adds an inital workbook set objMasterWB = objExcel.workbooks.add() 'Removes all sheets but 1 beause you must have atleast 1 active sheet Do While objMasterWB.Sheets.Count - 1 objMasterWB.Sheets(1).delete Loop Dim i 'Loops through the array For i = 0 to UBound(aryFilesToOpen) 'Opens file as new workbook Set objTmpWB = objExcel.workbooks.open(aryFilesToOpen(i)) 'Selects sheet 1 objTmpWB.Sheets(1).Select 'Copys Sheet 1 to master workbook objTmpWB.Sheets(1).Copy(objMasterWB.Sheets(1)) 'Close Book objTmpWB.Close(false) Next 'Deletes a trailing sheet objMasterWB.Sheets(objMasterWB.Sheets.Count).delete 'Saves file, you can specify somewhere here to always override without prompting objMasterWB.SaveAs(strSaveLocation) 'Close Book objMasterWB.Close(false) 'Close Excel objExcel.Quit() 'Remove Process set objExcel = nothing </script>
And Yes i did test and it does work!
Reply With Quote
  #3 (permalink)  
Old 09-21-2007, 08:26 AM
heavydee heavydee is offline
Junior Member
 
Join Date: Sep 2007
Posts: 2
heavydee is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default Good job

Perhalps i should just accept the fact that ill never be good at scripting let alone writing complex codes. In retrospect your code looks easy and it gets the job done. Thanks a lot.

How do i get to learn scripting ? I dont wanna give up. Where is the starting point for a dummy like me
Reply With Quote
  #4 (permalink)  
Old 09-21-2007, 05:55 PM
ALL's Avatar
ALL ALL is offline
Senior Member
 
Join Date: Oct 2006
Location: Sturgis, SD
Posts: 145
ALL is on a distinguished road
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default

My first language was Visual Basic for Applications (VBA) which technically wasnt a language but a macro language. I learnt the basics of variables and syntax then moved on to VB6 and then VB.NET then to PERL then PHP and then JavaScript. So in a sense I am a language hopper.

Where to start.... hmmm.... VBA is a good place to start or VBS is also a good place. Just start somewhere by taking a project you want to do and then go around online and look at code samples of how other people did it. When you have a semi-working model walk through it and try and figure out how it did it. Analize every little piece of code and figure out if it is necessary, and why it's there.

That's kinda how I did it. But i started when I was 15
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:25 AM.


Creative Commons License
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30