+ Reply to Thread
Results 1 to 6 of 6

Import specific line from external data

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Import specific line from external data

    Hello everyone,

    I was wondering how I can import a specific line from an external file.
    The code in the added example comes from this post:
    http://www.excelforum.com/word-progr...al-data.html#5

    Save both files in the same location, open the doc file and press the Test_Field text box.
    On this form load the external data. This will load the first line from the external file.

    How can the code be changed so it loads the second line from the external file? Or the third, etc.

    This is the code to import the file:
    Please Login or Register  to view this content.
    Kind regards,

    Marco
    Attached Files Attached Files

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Import specific line from external data

    Perhaps you could explain what you're trying to achieve? With what I've provided so far, there is no need for the data to be on separate lines. FWIW, your previous code already had the logic for reading multiple lines from a text file but I removed it as the approach I posted only requires a single data line (consistent, in fact, with what your code aimed to achieve with the Const declaration)
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Import specific line from external data

    I added an example how it worked before the changes. This still requires the trusted access, of course.
    With this it was possible to have multiple listbox entries with one external source.
    If you open the form, depending on the selection in ListBox1 (Test1), other entries will be loaded in ListBox2 (Test2).

    I was wondering if that's possible with your code as well? Or should I go for multiple external data files?

    Kind regards,

    Marco
    Attached Files Attached Files

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Import specific line from external data

    For one possible approach, see attached.
    Attached Files Attached Files

  5. #5
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Import specific line from external data

    Thanks for the reply.
    With that it shows the 2 lines over the 2 listboxes.
    What I would like to have is, depending on what the selection is in ListBox1, import another line in ListBox2.

    So let's say in the External Data file this is present:
    Please Login or Register  to view this content.
    In ListBox1, line 1 should be imported.
    Whenever someone picks number 1, line 4 should be imported in ListBox2 (A, B, C)
    If someone picks two, line 7 should be imported in ListBox2, etc.

    I want to specify in the import code which line should be imported from the text file.

    I can make the conditions, I only would like a code where I can specify the line to import.

    Kind regards and thanks for the time.

    Marco
    Last edited by Marco-Kun; 08-01-2012 at 09:04 PM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Import specific line from external data

    It would be more trouble than it's worth to conditionally read the file. What you can do is to load all the data into a string variable or array, then conditionally populate a listbox with the portion you're interested in. See attached. Note the data re-arrangement in the text file - and the way they're processed.
    Attached Files Attached Files

+ 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