Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Importing text via VBA into a VBA project? Can this be done

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi everyone...
    In reference to this topic:
    http://www.mrexcel.com/board/viewtop...5978&forum=2&2
    I am trying to import a text file into a VBA project...
    The text file would be in the activeworkkbook path and named DeleteOld.txt
    Thanks for any help,
    Tom

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Jay gave this guy a solution, but I would still like to know how to import a text file into a VBA project if possible...
    Thanks again,
    Tom

  3. #3
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default

    Hi TsTom. You mean like this?

    Sub Test()
    With ActiveWorkbook.VBProject
    .VBComponents.Import FileName:=ActiveWorkbook.Path & "DeleteOld.txt "
    End With
    End Sub

  4. #4
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default

    Please modify the character "" in code.
    mean chr(&H5C).
    I could not input the character from my pc.

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Colo

    One further question...
    In the following code, how might I get around the compile error?

    The following will load TestImport.bas dynamically....

    Sub TryImport()
    Application.VBE.ActiveVBProject.VBComponents.Import "C:TestImport.bas"
    TestRun
    End Sub
    Here are the contents of TestImport.bas:

    Sub TestRun()
    Sheet2.Range("A1") = "Did It"
    End Sub
    Problem is with the first procedure, Sub TryImport().
    I get an obvious compile error with the call to "TestRun" because the module containing the procedure does not exist in the project until it is loaded.

    I checked into Conditional Compilation and it did not seem to be what I needed...
    Any other ideas?

    Thanks again,
    Tom

  6. #6
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default

    Hello again! In this case, I always use "OnTime Now"
    Pls try this.

    Sub TryImport()
    With Application
    .VBE.ActiveVBProject.VBComponents.Import "C:TestImport.bas"
    .OnTime Now, "TestRun"
    End With
    End Sub

    Regards,
    Colo

  7. #7
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Colo,
    Works perfectly.
    Tom

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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