Import a .bas file into a specified workbook.

Darren Bartrup

Well-known Member
Joined
Mar 13, 2006
Messages
1,297
Office Version
  1. 365
Platform
  1. Windows
Hi all,

At work I have a folder full of .bas files containing useful UDF's.
At the moment I am the only person in my team that makes use of these files as importing a .bas file is beyond the rest of the team (i.e. then know it contains code so they get scared).

What I'd like to do is create a workbook where they can select one of the files (each file contains a single UDF), maybe see what it does (I put an explanation in the Comments section of the properties for each file) and then have it automatically imported into the workbook of their choice so they can make use of these functions.

Could anyone help with the code needed to import the file and the code to see the comments please?
 
...

Looking forward to see the improvements on this topic:-)

There's always room for improvement, you know-it's the biggest room in the house.

Tried your suggestion, got stuck within the loop, not that VBA superduperuser as I might think:-)
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi

Following on from this thread, is there a way you can

Import all 'bas' files in a folder to a new excel spreadsheet.

If you have say 30 modules in one spreadsheet and you want to export them all to another spreadsheet,

I have the code below, and I get an error in the line:

fn.FoundFiles.Import _
Filename:="L:" & "\" & "book2" & ".xls"


Sub ImportAllVBA()

'Need to change code


Dim fs As FileSearch, ws As Worksheet, i, j As Long
Dim f, mySubFolders, aFolder
'Dim VBComp As VBIDE.VBComponent
Set fs = Application.FileSearch

With fs
.SearchSubFolders = False ' set to true if you want sub-folders included
' .FileType = msoFileTypeAllFiles 'This lists all files


fn = InputBox("Which directory do you want files from?", , "L:\VBAcode\")
.LookIn = fn
'.LookIn = "L:\" 'modify this to where you want to search
If .Execute > 0 Then

'Set ws = Worksheets.Add
Workbooks("book2.xls").Activate

For i = 1 To .FoundFiles.Count

fn.FoundFiles.Import _
Filename:="L:" & "\" & "book2" & ".xls"

Next

End If

End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,225,116
Messages
6,182,926
Members
453,140
Latest member
SAbboushi

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