About Miguel Zapico Expertise I can answer question about how to use scripts to consolidate data, connect different systems and automate tasks. I have no experience on using VBScript on web programming.
Experience I have been using VBScript and Windows Scripting Host as my swiss tool for the last 6 years.
Organizations New York PC users group (NYPC)
Independant Computer Consultants Association (ICCA)
Education/Credentials Microsoft MCSE in Windows NT
I am trying to open an excel worksheet, paste data that will be in the clipboard to sheet 2. Then copy the data from D1-D3, move to sheet 1, paste the data in C3, print sheet 1, and close the excel worksheet WITHOUT saving the changes. Here is my script, which is not working for me. I am using Macro Scheduler by MJNet.
VBSTART
Option Explicit
Sub QTTankReport
Dim xlApp
Dim xlBook
Dim xlSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("c:My DocumentsQT Tank Gauge.xls")
Set xlSheet = xlBook.Worksheets("Sheet2")
Range("D1:D46").Copy
set xlSheet = xlBook.Worksheets("Sheet1")
Range("C3").Select
Paste
PrintOut Copies=1, Collate=True
wb.Close False
End Sub
Answer I have tweaked the script, the main issue is that you are declaring and setting the objects but you are not using them afterwards. See also some comments on the body.
I have done this with Notepad:
VBSCRIPT
QTTankReport 'Call the sub
Sub QTTankReport
Dim xlApp
Dim xlBook
Dim xlSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("c:\My Documents\QT Tank Gauge.xls")
Set xlSheet = xlBook.Worksheets("Sheet2")
xlapp.visible = true 'For debug purposes, show the Excel window
xlSheet.Range("D1:D46").Copy
set xlSheet = xlBook.Worksheets("Sheet1")
xlSheet.Activate 'The sheet needs to be active
xlSheet.Range("C3").Select
xlSheet.Paste
xlSheet.PrintOut , , 1, , , , True 'In the script, better use the long format
xlBook.Close False