+ Reply to Thread
Results 1 to 4 of 4

Excel2000: Weird behaviour in VBA

  1. #1
    Arvi Laanemets
    Guest

    Excel2000: Weird behaviour in VBA

    Hi

    When writing a VBA procedure, somehow I can't refer to workbooks by their
    name anymore.
    P.e. in Watch window
    Workbooks("ReadRep")
    returns an error "Subscript out of range". At same time p.e.
    Workbooks(1)
    works.

    So I have to use p.e.
    Workbooks(1).Sheets("Raport").Range("B6:H" & [RowCount] +
    5).ClearContents
    instead of
    Workbooks("ReadRep").Sheets("Raport").Range("B6:H" & [RowCount] +
    5).ClearContents
    , but I can never be sure, that there were no workbooks opened before.

    Another odd thing: I needed in 2 columns to replace all commas with periods.
    The code
    ActiveWorkbook.Range("G:H")..Replace What:=",", Replacement:=".",
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False
    did return an error. I tried
    ActiveWorkbook.Range("G:H").Select
    Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False
    , and
    ActiveWorkbook.Columns("G:H").Select
    Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False

    , and again did get an error - on Select command. The error message was
    "Run-time error '438': Object doesn't support this property or method"


    Has someone a clue, what is going on?
    Thank in advance!

    --
    Arvi Laanemets
    ( My real mail address: arvi.laanemets<at>tarkon.ee )



  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    It sounds like you have the code in a different spreadsheet to the one on which you want to operate - but I would have thought you had noticed that.

    You could check using activeworkbook.name and thisworkbook.name but again I would have thought you would have noticed this.

    Regards

  3. #3
    Arvi Laanemets
    Guest

    Re: Excel2000: Weird behaviour in VBA

    Hi

    The code was in active workbook, but your tip did gave me a start anyway. I
    had to refer to workbook usinf it's name with extension. I.e.
    Workbooks("ReadRep.xls") instead Workbooks("ReadRep"), etc. Strange, from MS
    Help :
    Workbooks Property Example
    This example activates the workbook Book1.xls.
    Workbooks("BOOK1").Activate

    And with replace was my fault too - I did forget to determine the worksheet
    :-((


    --
    Arvi Laanemets
    ( My real mail address: arvi.laanemets<at>tarkon.ee )



    "tony h" <[email protected]> wrote in
    message news:[email protected]...
    >
    > It sounds like you have the code in a different spreadsheet to the one
    > on which you want to operate - but I would have thought you had noticed
    > that.
    >
    > You could check using activeworkbook.name and thisworkbook.name but
    > again I would have thought you would have noticed this.
    >
    > Regards
    >
    >
    > --
    > tony h
    > ------------------------------------------------------------------------
    > tony h's Profile:
    > http://www.excelforum.com/member.php...o&userid=21074
    > View this thread: http://www.excelforum.com/showthread...hreadid=507142
    >




  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    Glad to be of help. You may notice that a new workbook does not have a .xls extension it is only once it has been saved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1