Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Load a .bas file into a project

Load a .bas file into a project

Load a .bas file into a project

Hello VB Members,

I posted in an old thread that was about "how to import a file to a vb project"

I think I was not clear enough to make people understand.

The thing is...

I have made a code that loops through "*.xls" files.
For each xls file the loop imports a "*.bas" file located here "C:\test\test.bas"

The function runs "RUNME" inside the "*.bas"

The actual problem

Instead of an absolute path to the "*.bas" file I want to import the "*.bas" file into my vb project.

The "*.bas" file should be imported to the vb project.

I want to import the "*.bas" file to the vb project, regardless of computer.

see code below:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myfile = "C:\test\test.bas"

        FolderBrowserDialog1.SelectedPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        FolderBrowserDialog1.ShowNewFolderButton = True 'folderdialog button
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim mySelFile As String = FolderBrowserDialog1.SelectedPath
            Dim intcount As Integer = Nothing
            Tb_FilePath.Text = mySelFile
            If Not IO.Directory.GetFiles(mySelFile, "*.xls").Any() Then
                MsgBox("there are no xls files here")
            End If
            For Each filename As String In IO.Directory.GetFiles(mySelFile, "*.xls") 'I define the type of all files the loop go through

                excelApp.Visible = True

                ' Create a new instance of Excel and make it visible.
            '     MsgBox("Modified (" + intcount.ToString + ") Excel files")

            'if the user has not selected a folder, it is a warning
            MsgBox("No Folder selected", MsgBoxStyle.Exclamation, "No selected folders")
        End If
End sub 

I have imported the file as an resource test.bas

I have tested with this code but I guess I need to declare it but I don't know how:

see codesnippet:


Dim myfile As String
        myfile = My.Resources.test.bas 

Could someone help me?

Thank you in advance.

RE: Load a .bas file into a project

Are you saying that you have the filename as a string resource? Or the actual contents of the bas file as a string resource?

RE: Load a .bas file into a project

Well I guess my code could be very wrong I am newbeginner..


Dim myfile As String
myfile = My.Resources.test.bas 

maybe something with this?


Dim myfile As String
        myfile = My.Resources.ResourceManager.GetObject("test.bas") 

the problem is I want just use call the "test.bas" file so excel import the resource file test.bas file.

RE: Load a .bas file into a project

You need to answer the question first. Is the resource the contents of the file, or is the resource the filename? If the former, then the following code snippet illustrates what you need to do. Note that it is illustrative only (e.g. it creates a new workbook, and a temporary new module):


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim excelApp As Microsoft.Office.Interop.Excel.Application
        Dim workingmodule As String
        Const vbext_ct_StdModule = 1

        excelApp = New Microsoft.Office.Interop.Excel.Application

        workingmodule = excelApp.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_StdModule).Name
    End Sub 

RE: Load a .bas file into a project

I dont understand your question

inside the bas file is vba code. (Excel macro)

RE: Load a .bas file into a project

Elmnas, there is often pain in progress.

RE: Load a .bas file into a project

that is not the answer I am looking for :)

RE: Load a .bas file into a project

>I dont understand your question.

Fortunately your screenshot answers the question - the resource is the contents of the file, so my example code (which made that assumption) would work. Depending on the contents of that file, of course. And one assumes that you realise that for my example I happened to use a resource that I called RunMe, whilst yours is called Test, so you'd need to change:




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close