+ Reply to Thread
Results 1 to 4 of 4

Is it possible to replace 'ActiveSheet' by 'Sheets(strImported)' ??????????

  1. #1
    Registered User
    Join Date
    12-26-2004
    Posts
    5

    Post Is it possible to replace 'ActiveSheet' by 'Sheets(strImported)' ??????????

    Hi guys

    I need this line in my macro. What it does is, importing a textfile.

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & vFilename, _
    Destination:=Range("A1"))

    What I want to do is to replace 'ActiveSheet' by 'Sheets("Import")' or something like that.
    I hate the idea that I first need to select the sheet, and then Import the data.

    Is this possible? Because with the 'Sheets("Import") method I get the error:

    "The destination range is not on the same worksheet that the Query table is being created on."

    Please let me know.
    Thanx

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Instead of 'Sheets("Import")', you should use Sheets("Import") (without the single quotation mark.

    Alternative, you could use the CodeName instead of the Tab name for the worksheet. You can see the code name in the Project Explorer window of VB Editor. You will see something like this: Sheet1 (Import)

    The command would then be: Sheet1.QueryTable .....

  3. #3
    Registered User
    Join Date
    12-26-2004
    Posts
    5

    Missing the point....

    Hi,

    I know about the quotes, don't worry about them. The point is, that when I USE the Sheets("something") instead of Activesheet... then I get a error message. So I'm doing something wrong... and I want to know what that is.

    Greetz,
    Vernon

  4. #4
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    you are right ... I missed the point

    OK ... I can't tell exactly what it is you are trying to do ... so I'm not too surprised that VB is similarly confused.

    I suggest dimensioning some variables. Then set the variables one at a time and step through the routine finding out which variable is not setting set.

    One thing that is not clear is Range("A1"). Is that Range("A1") on the active sheet or the "something" sheet? Since you don't specify, the default is the active sheet. That might be the entire problem right there.

+ 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