473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

vbscript problem

Hi All

I have a vbscript problem, I am trying to lop through all excel files in folders and subfolders and if a certain range ie F60 is less than or equal to 2 either printout the document or save to a specific location.

any help would be appriciated.

Set oShell = CreateObject("Wscript.Shell")
strUserProfile = oShell.ExpandEnvironmentStrings("%USERPROFILE%")

strPath = strUserProfile &"\Desktop\Excel_Files_To_Print"

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder (strPath)

For Each objFile In objFolder.Files

If objFso.GetExtensionName (objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
objworkbook.worksheets("Assessment").Activate

objworkbook.worksheets("Assessment").cells(F60).va lue = <3

objWorkbook.worksheets("Assessment").Printout
objWorkbook.Close True 'Save changes
End If

Next

objExcel.Quit

Graham
Jun 23 '09 #1
5 1943
What is the problem?
Jun 24 '09 #2
Hi

Sorry didnt realise I hadnt said :P

This part isnt working

If objFso.GetExtensionName (objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
objworkbook.worksheets("Assessment").Activate

objworkbook.worksheets("Assessment").cells(F60).va lue = <3

objWorkbook.worksheets("Assessment").Printout
objWorkbook.Close True 'Save changes
End If

I need it to check the range to see if it is under 3 then print or save as if this condition is met.

Thanks for looking

Graham
Jun 24 '09 #3
Not much wrong really, you missed a "if/then" statement to print the workbook yes or no, and you used "cells" instead of "range" to point to the location of the cell in the sheet. Range always requires quotes "F60" if not populated as variable.

if it does not work on your side then let me know the errormessage.

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder (strPath)

For Each objFile In objFolder.Files

If objFso.GetExtensionName (objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
objworkbook.worksheets("Assessment").Activate

objworkbook.worksheets("Assessment").Range("F60"). value = <3

objWorkbook.worksheets("Assessment").Printout
objWorkbook.Close True 'Save changes
End If

Next

objExcel.Quit
Jun 24 '09 #4
Sorry, wrong code! find the correct code below

For Each objFile In objFolder.Files

If objFso.GetExtensionName(objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
naam = objWorkbook.Name
objWorkbook.worksheets("Assessment").Activate
If objWorkbook.worksheets("Assessment").Range("F60"). Value <= 3 Then
objWorkbook.worksheets("Assessment").Printout
End If

objWorkbook.Close 'True 'Save changes
End If

Next
Jun 24 '09 #5
Hey

That is good it works fine but.... :)

I Need it to check more than one range as there are different versions of the same spreadsheet ie this isnt working as it keeps printing them all??

For Each objFile In objFolder.Files

If objFso.GetExtensionName(objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
naam = objWorkbook.Name
objWorkbook.worksheets("Assessment").Activate
If objWorkbook.worksheets("Assessment").Range("D56"). Value <3 or objWorkbook.worksheets("Assessment").Range("E55"). Value <3 or objWorkbook.worksheets("Assessment").Range("D45"). Value <3 Then
objWorkbook.worksheets("Assessment").Printout
End If

objWorkbook.Close 'True 'Save changes
End If

Next


also how can I tell it to check all subfolders as well?

Thanks for the help so far.

Graham
Jun 24 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tash Robinson | last post by:
Hi I am kind of new to active-x programming, and need a point in the right direction. I have an active-x control that I wrote in VB6. I wrote a testbed in VB and everything seems to work OK....
2
by: Frank | last post by:
When I used IE 6.0 to view the ASP page on Window 2000 server PC, I encountered the error message: "Expected end of statement". The ASP page code is as:...
8
by: Dave Thomas | last post by:
I have developed a web site using asp pages that use both vbscript and javascript. Run the site on my PC and everything is fine. Ftp to my web hosting provider which hosts asp pages and look on my...
1
by: Ana Rita | last post by:
Hello to all. I'm trying to do call a vbscript sub in one page aspx. My vbscript sub is in a file with the extension (vbs) and it looks like this: Sub Mens (strmens) Msgbox strmens
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
3
by: Joe Caverly | last post by:
Hi, I'm using Visual C++ 32-bit Professional Edition 5.0 Using Microsoft Knowledge Base Article 181473 as a basis, I'm trying to transform this VB Code; Dim sc As Object Dim code As String...
2
by: duncan | last post by:
why does this work :- <HEAD> ...... <SCRIPT LANGUAGE="javascript"> function test() { alert("test 1") } </SCRIPT>
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
6
by: rishabhshrivastava | last post by:
Hello All, I am using ASP.NET 2.0 and I am experiencing a problem using vbscript that is this script on client side is preventing the postback of my controls. I have a dropdownlist which is...
0
by: rizzy | last post by:
Hello, didn't know where to post this, since you don't have a vbscript section. I thin k however that this applies to javascript as well. I have an asp.net web application which allows the staff...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.