+ Post New Thread
Results 1 to 7 of 7
Windows Thread, Writing to Excel from .vbs script in Technical; Hi Again Writing a script that will put some data into an excel document then display it on screen, however ...
  1. #1
    Samson's Avatar
    Join Date
    Mar 2007
    Location
    Wales
    Posts
    201
    Thank Post
    7
    Thanked 1 Time in 1 Post
    Rep Power
    17

    Writing to Excel from .vbs script

    Hi Again

    Writing a script that will put some data into an excel document then display it on screen, however when the script runs it says "Object Required: Excel"...


    ... any ideas?

    Code:
    Dim ExcelSheet
    ExcelSheet = CreateObject(Excel.Application)
    Excelsheet.Application.Visible = True
    ExcelSheet.Application.Cells(1,1) = "Username"
    ExcelSheet.Application.Cells(1,2) = "Date"
    ExcelSheet.Application.Cells(1,3) = "Time"
    ExcelSheet.Application.Cells(1,4) = "Machine Name"
    ExcelSheet.SaveAs "QuerybyUser" & qUserN & Replace(Date,"/","") & ".xls"
    ExcelSheet.Application.Quit
    Set ExcelSheet = Nothing

    Thanks

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,270
    Thank Post
    884
    Thanked 2,747 Times in 2,321 Posts
    Blog Entries
    11
    Rep Power
    785
    You may need to declare the creation object as a method of wscript in your code first ie:
    Code:
    Dim objXL
    Set objXL = WScript.CreateObject("Excel.Application")
    
    objXL.Visible = TRUE
    
    objXL.WorkBooks.Add
    Automate Excel In Vbscript

    edit:- Post2: combined from latter post

    did you remember to put set in front of your application assignment?

    Code:
    Set ExcelSheet = WScript.CreateObject(Excel.Application)
    Last edited by SYNACK; 7th October 2008 at 04:31 PM.

  3. #3
    Samson's Avatar
    Join Date
    Mar 2007
    Location
    Wales
    Posts
    201
    Thank Post
    7
    Thanked 1 Time in 1 Post
    Rep Power
    17
    No effect, still the "Object Required: Excel" error.... odd.

  4. #4
    Samson's Avatar
    Join Date
    Mar 2007
    Location
    Wales
    Posts
    201
    Thank Post
    7
    Thanked 1 Time in 1 Post
    Rep Power
    17
    Quote Originally Posted by SYNACK View Post
    did you remember to put set in front of your application assignment?

    Code:
    Set ExcelSheet = WScript.CreateObject(Excel.Application)
    I did

  5. #5

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,270
    Thank Post
    884
    Thanked 2,747 Times in 2,321 Posts
    Blog Entries
    11
    Rep Power
    785
    Obvious question but is excel installed on the machine that you are running the script on?

  6. #6
    Samson's Avatar
    Join Date
    Mar 2007
    Location
    Wales
    Posts
    201
    Thank Post
    7
    Thanked 1 Time in 1 Post
    Rep Power
    17
    Quote Originally Posted by SYNACK View Post
    Obvious question but is excel installed on the machine that you are running the script on?

    Indeed it is..

    Actually..

    The script is stored on the server, but I'm running it locally.... wouldn't make a difference would it?

  7. #7

    Join Date
    Jul 2007
    Location
    Nottingham
    Posts
    198
    Thank Post
    19
    Thanked 7 Times in 7 Posts
    Rep Power
    16
    Running from a server location shouldn't make any difference, below is an example of opening excel:

    dim objExcel, objWorkbook, objWorksheet, strCellValue

    'Launch Excel
    Set objExcel = CreateObject("Excel.Application")

    'Set Excel to be visible
    objExcel.Application.Visible = True

    'Open a workbook
    Set objWorkbook = objExcel.Workbooks.Open("C:\UCv2\userlistv2.xlsx")

    'Select a worksheet
    Set objWorksheet = objWorkbook.Worksheets(1)

    'Get the value of cell A1
    strCellValue = objExcel.Cells(1, 1).Value

    'Put the value of strCellValue into cell A1
    objWorksheet.Cells(1, 1).Value = strCellValue

    'Save the workbook,
    objWorkbook.Save

    'Quit Excel
    objExcel.Quit



SHARE:
+ Post New Thread

Similar Threads

  1. Sub within a sub - VBS Script
    By FN-GM in forum Scripts
    Replies: 5
    Last Post: 18th May 2008, 07:30 PM
  2. VBS Script to copy a folder
    By FN-GM in forum Scripts
    Replies: 2
    Last Post: 23rd February 2008, 02:08 PM
  3. Trace a VBS Script
    By chalkwellstu in forum Scripts
    Replies: 2
    Last Post: 25th January 2008, 11:53 AM
  4. VBS Drive script is running from
    By Samson in forum Scripts
    Replies: 5
    Last Post: 10th May 2007, 04:29 PM
  5. Help needed writing a pkinvoice script
    By Ric_ in forum Scripts
    Replies: 6
    Last Post: 20th April 2007, 01:15 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •