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

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

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