Results 1 to 2 of 2

Thread: VBScript fails

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    VBScript fails

    Hello,

    Not sure why the script fails on the marked line below.

    Code:
    sPath = "c:\tmp\"
    fln = sPath + "tmp.pptm"
    strExcelPath = sPath + "tmp.xlsm"
    Set objExcel = CreateObject("Excel.Application")
    ' sheet1 - MAIN
    ' sheet2 - Simulations_journal
    ' sheet3 - Misc
    
    objExcel.Workbooks.Open strExcelPath
    objExcel.Visible = True
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
    
    With objExcel
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
    LastColumn = objSheet.Cells(1, .Columns.Count).End(xlToRight).Columnc'<======== fails here
    LastRow = objSheet.Cells(.Rows.Count, 4).End(xlUp).Row
    End With
    
    pako = CStr(LastRow) + Chr(10) + CStr(LastColumn)
    
    
    objExcel.Cells(LastRow + 2, 1).Value = Now
    objExcel.Cells(LastRow + 2, 2).Value = Now
    objExcel.Cells(LastRow + 2, 3).Value = ThisWorkbook.Name
    objExcel.Cells(LastRow + 3, 3).Value = ThisWorkbook.path
    objExcel.Cells(LastRow + 4, 3).Value = Sheets("MAIN").Cells(20, 5).Value
    objExcel.Cells(LastRow + 5, 3).Value = Sheets("MAIN").Cells(21, 5).Value
    objExcel.Cells(LastRow + 6, 3).Value = Sheets("MAIN").Cells(22, 5).Value
    objExcel.Cells(LastRow + 7, 3).Value = Sheets("MAIN").Cells(23, 5).Value
    objExcel.Cells(LastRow + 8, 3).Value = Sheets("MAIN").Cells(24, 5).Value
    objExcel.Cells(LastRow + 9, 3).Value = Sheets("MAIN").Cells(25, 5).Value
    objExcel.Cells(LastRow + 10, 3).Value = Sheets("MAIN").Cells(26, 5).Value
    ' Excel Save, Quit and Unload
    objExcel.DisplayAlerts = False
    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close
    objExcel.Application.Quit
    objExcel.DisplayAlerts = True
    Set objExcel = Nothing

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,246

    Re: VBScript fails

    Are xlToRight and xlUp defined somewhere?

    Typo in the .Column property?
    Code:
    LastColumn = objSheet.Cells(1, .Columns.Count).End(xlToRight).Columnc  '<======== fails here

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width