Windows Vista Forums

From Excel VBA to vbScript
  1. #1


    OldDog Guest

    From Excel VBA to vbScript

    How would I convert this macro to vbScript?

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    Range("AQ157").Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).Select
    End Sub


    So far I have

    xl.cells("AQ157").Select
    xl.Selection.End(xlDown).Select

    'This is the line I am having problems with:
    xl.Range(Selection, Selection.End(xlDown)).Select
    'This is the error:
    ' Microsoft VBScript runtime error: Object required: 'Selection'

    TIA,



    OldDog

      My System SpecsSystem Spec

  2. #2


    Tom Lavedas Guest

    Re: From Excel VBA to vbScript

    On Apr 16, 12:11*pm, OldDog <mikef2...@newsgroup> wrote:

    > How would I convert this macro to vbScript?
    >
    > Sub Macro1()
    > '
    > ' Macro1 Macro
    > '
    > * * Range("AQ157").Select
    > * * Selection.End(xlDown).Select
    > * * Range(Selection, Selection.End(xlDown)).Select
    > End Sub
    >
    > So far I have
    >
    > * *xl.cells("AQ157").Select
    > * *xl.Selection.End(xlDown).Select
    >
    > 'This is the line I am having problems with:
    > * *xl.Range(Selection, Selection.End(xlDown)).Select
    > 'This is the error:
    > ' * Microsoft VBScript runtime error: Object required: 'Selection'
    >
    > TIA,
    >
    > OldDog
    Something like this, I think (though I haven't analyzed what it is
    supposed to accomplish, exactly - just addressed the syntax issue) ...

    Const xlDown = -4121
    xl.cells("AQ157").End(xlDown).Select
    xl.Range(xl.Selection, xl.Selection.End(xlDown)).Select
    _____________________
    Tom Lavedas

      My System SpecsSystem Spec

  3. #3


    Reventlov Guest

    Re: From Excel VBA to vbScript

    Il giorno Fri, 16 Apr 2010 13:33:51 -0700 (PDT), Tom Lavedas <tglbatch@newsgroup> ha
    scritto:

    >Something like this, I think (though I haven't analyzed what it is
    >supposed to accomplish, exactly - just addressed the syntax issue) ...
    >
    >Const xlDown =3D -4121
    > xl.cells("AQ157").End(xlDown).Select
    > xl.Range(xl.Selection, xl.Selection.End(xlDown)).Select
    Obviously (?) at the top "XL" should be declared
    set xl=createobject("excel.application")
    This is useful as far as he is stuck on the "selection object required".

    --
    Giovanni Cenati (Bergamo, Italy)
    Write to "Reventlov" at katamail com
    http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
    --

      My System SpecsSystem Spec

  4. #4


    OldDog Guest

    Re: From Excel VBA to vbScript

    On Apr 16, 1:48*pm, no...@newsgroup (Reventlov) wrote:

    > Il giorno Fri, 16 Apr 2010 13:33:51 -0700 (PDT), Tom Lavedas <tglba...@newsgroup> ha
    > scritto:
    >

    > >Something like this, I think (though I haven't analyzed what it is
    > >supposed to accomplish, exactly - just addressed the syntax issue) ...
    >

    > >Const xlDown =3D -4121
    > > *xl.cells("AQ157").End(xlDown).Select
    > > *xl.Range(xl.Selection, xl.Selection.End(xlDown)).Select
    >
    > Obviously (?) at the top "XL" should be declared
    > set xl=createobject("excel.application")
    > This is useful as far as he is stuck on the "selection object required".
    >
    > --
    > Giovanni Cenati (Bergamo, Italy)
    > Write to "Reventlov" at katamail comhttp://digilander.libero.it/Cenati(Esempi e programmi in VbScript)
    > --
    I gave the code a try and I get this err:

    E:\Scripts\VBS\Test_Find.vbs(37, 2) Microsoft VBScript runtime error:
    Unknown runtime error

    Here is my script so far:

    Const ForReading = 1
    Const xlCellTypeLastCell = 11
    Const xlFormulas = -4123
    Const xlPart = 2
    Const xlByRows = 1
    Const xlNext = 1
    Const xlDown = -4121

    strPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") &
    "test.xls"
    boolMatchCase = False

    Set xl = CreateObject("Excel.Application")
    xl.Visible = True
    xl.DisplayAlerts = FALSE

    Set wb = xl.Workbooks.Open(strPath)
    Set ws1 = wb.Worksheets(1)
    Set ws2 = wb.Worksheets(2)
    ws1.Activate

    Set objRange = ws1.UsedRange
    objRange.SpecialCells(xlCellTypeLastCell).Activate
    intNewRow = XL.ActiveCell.Row + 1
    strNewCell = "A" & intNewRow

    Set mainRng = ws1.UsedRange.Cells
    ColCount = mainRng.Columns.Count
    RowCount = mainRng.Rows.Count
    For R = 1 To mainRng.Rows.Count
    For C = 1 To mainRng.Columns.Count

    If ws1.Cells(R,C).Value = "IsInstalled" Then
    ws1.Cells(R,C).Select
    wscript.echo R & vbTab & C

    xl.cells("AQ157").End(xlDown).Select '< -- this is line 37
    xl.Range(xl.Selection, xl.Selection.End(xlDown)).Select

    End If

    '< ----- end script

    Eventually I want to replace ("AQ157") with (R,C)

      My System SpecsSystem Spec

From Excel VBA to vbScript problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to copy large data from one excel to another using VBScript Davo VB Script 0 01 Jan 2010
Exporting MsSQL table to Excel using vbScript? StephaneLeFou VB Script 0 19 Mar 2009
Vbscript to Search Excel Codeblack VB Script 12 29 Jan 2009
VBscript applying borders in Excel Codeblack VB Script 0 11 Sep 2008
new to excel and vbscript - need help thewhizkid VB Script 3 30 May 2008