[RESOLVED] VB6 - Excel.Selection.Sort-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] VB6 - Excel.Selection.Sort

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    294

    Resolved [RESOLVED] VB6 - Excel.Selection.Sort

    I made a program that takes in an excel file, then formats it the way it's supposed to look for my job, and saves it. It works great until a certain point. The first time you load a file into it and have it converted it works fine...after the conversion, though, when you load the next file and convert it I get an error on this line:

    Code:
        objExcel.Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    The error I'm getting is:

    "Method 'Range' of object '_Global' failed"

    Does anyone know why this might be the case? I can't imagine what happens between the first conversion and the second conversion that causes that line not to work!

    Thanks guys, appreciate it!
    Last edited by fEtchboi88; Jun 26th, 2008 at 03:20 PM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    294

    Re: VB6 - Excel.Selection.Sort

    Never mind! haha

    I changed
    Code:
    Key1:=Range("F2")
    to
    Code:
    Key1:=objWorksheet.Range("F2")

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    36,790

    Re: [RESOLVED] VB6 - Excel.Selection.Sort

    The problem is that you have used Range("F2"), without specifying what it belongs to.

    As there is no Range object/function in VB, it causes lots of confusion, and thus bugs.

    You should be using a parent object, eg: objSheet.Range("F2")


    edit: slightly too slow it seems!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.