Excel VBA import .bas file starting in particular director help...

Eveck

New Member
Joined
Jan 11, 2013
Messages
4
Alright the code I have is:

Private Sub Auto_Open()
Application.DisplayAlerts = False
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose prior provider's text file to import", _
FileFilter:="Text Files *.txt (*.txt),")
''
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "No File!!!"
Exit Sub
Else
Workbooks.Open fiLename:=FileToOpen
End If
Set SourceBook = ActiveWorkbook
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Windows("Eric Parsing.xlsm").Activate
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
SourceBook.Close False
fiLename = Application.GetOpenFilename("Bas FIle(*bas),*bas", 1)
Application.VBE.ActiveVBProject.VBComponents.Import (fiLename)
Run "Macrox"
End Sub


Everything works fine... At the end when I am importing the .bas file I just want to have it start searching in directory "T:\Data\MacroP". Right now it just starts at my desktop. Any help??? THANK YOU!!!!!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
That will work at the beginning of the code but when after I select the appropriate file in my first text import regardless if I have the chdir in before importing the .bas file the directory sticks to where I imported my text from.
 
Upvote 0
Yeah here was the first attempt and it didn't result into a debug but ignored the command to change directory:

ChDir "T:\Data\MacroP"
fiLename = Application.GetOpenFilename("Bas FIle(*bas),*bas", 1)
Application.VBE.ActiveVBProject.VBComponents.Import (fiLename)

The second attempt I tried placing it into the code directly before getopenfilename:

fiLename = Application.ChDir "T:\Data\MacroP".GetOpenFilename("Bas FIle(*bas),*bas", 1)
Application.VBE.ActiveVBProject.VBComponents.Import (fiLename)

That gives me a Compile Error Expected: End of Statement or a Compile Error Syntax Error.
 
Upvote 0
Are the two paths on different drives?

Maybe something like:

Code:
ChDrive "c"
ChDir "c:\temp"
sFile = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
 
Upvote 0
I was able to get it to work the way I wanted. I changed the import sequence to import the .bas file first and had the directory changed at the beginning so it went to the folder where I had stored all my .bas files. Having the directory set for the .txt import wasn't a priority. Thanks for all your help!
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

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