Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

VBScripting for Ms Excel - AutoPrint a file

Avatar of bujumah
bujumahFlag for United Arab Emirates asked on
Windows BatchMicrosoft Legacy OSMicrosoft Applications
20 Comments1 Solution4599 ViewsLast Modified:
Hi,
This is simple but I could not do it myself.

An excel file is generated every night in a network directory @ 0030 and given a name (file-date-month_year.xls).
I need to copy and print that file automatically every day but could not find the code for wildcard or to select, open and print the latest file from the file list.

The code I'm using is:

 
'1) Copy the file from original location to print folder @ 00:35
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\location\file-03-07_2010.xls" , "C:\print\", OverwriteExisting


'2) Open and print the file C:\print\file-03-07_2010.xls @ 00:40
Dim objExcel, objWorkbook, strFile

' Connect to Excel
Set objExcel = CreateObject("Excel.Application")

' *******************************************
' Put the path and file name to print Here
' *******************************************
strFile  = "C:\print\file-03-07_2010.xls"

' Open the Excel File for Printing
Set objWorkbook = objExcel.Workbooks.Open _
    (strFile)

' Print to Default Printer
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.PrintOut

objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

Note: after searching in Google and EXP-EX I collected this code.

Would anybody help me of getting this sorted out or advice of a better way to do it please?

Thanks
Mohamed
ASKER CERTIFIED SOLUTION
Avatar of Bitsqueezer
BitsqueezerFlag of Germany image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answers