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

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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
 
Upvote 0
Hi TsTom. You mean like this?

Sub Test()
With ActiveWorkbook.VBProject
.VBComponents.Import FileName:=ActiveWorkbook.Path & "DeleteOld.txt "
End With
End Sub
 
Upvote 0
Please modify the character "" in code.
mean chr(&H5C).
I could not input the character from my pc.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top