CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VBA error

  1. #1
    Join Date
    Mar 2001
    Posts
    3

    VBA error

    Hi all,
    I have the following VBA code in the macro for my Excel SpreadSheet, but the macro is giving an error " RunTime error '1004', Application-defined or object-defined error".
    I am on Win2k, MS-Office2K.



    Range("B3").Select
    Selection.QueryTable.Refresh BackgroundQuery:=false


    The error points to the second line i.e. "Selection..."
    I would also add that I am a newbee to VB, my strengts lie elsewhere. This was needed to upload some data to the spreadsheet

    TIA

    Ajay K


  2. #2
    Join Date
    Jun 1999
    Location
    England
    Posts
    86

    Re: VBA error

    Hi Ajay,

    I am going to assume that the spreadsheet you are trying to run this macro on contains a table which is linked to an external data source, yes?

    If it is then fine, if it isn't the macro won't work. The macro is attempting to refresh the cells in the spreadsheet with the data stored externally. Also you need to make sure that the cell address is part of the table. i.e. If you applied B3 and it is not part of the table Excel will return the message you are getting.

    I tried this and it worked first time

    Worksheets(1).Range("a1").QueryTable.Refresh

    Best of luck
    Andy



  3. #3
    Join Date
    Mar 2001
    Posts
    3

    Re: VBA error

    Andy,
    Thanks Man, that really helped. It worked, I was having trouble with the ODBC.

    Thanks
    Ajay


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

Featured