Saving Text File

C

cmungs

Hi all,
I need some help with a macro that saves a worksheet as a text file when
called. My issue that I am currently having is getting the text file to save
in the same directory that the original excel spreadsheet was located instead
of the default location. I am admittedly a novice when it comes to VB so
please forgive me if I've made any glaring mistakes.

I've tried to use the curdir function, but without any real results. Again,
I want the "Export Sheet" to save as a text file in the same directory as the
original excel file. I'd like this to be a transparent operation for the
user so they don't "see" any of it happening...

Here is what my code looks like currently:

Sub save_as()


Application.ScreenUpdating = False
Application.DisplayAlerts = False

Sheets("ExportSheet").Select

Dim myPath As String
Dim myFile As String

myPath = curdir("J")
myFile = "import_file"
myFile = myFile & ".txt"

ActiveWorkbook.SaveAs Filename:=myPath & myFile, FileFormat:=xlText,
CreateBackup:=False

Sheets("Sheet1").Select
Sheets("import_file").Name = "ExportSheet"

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

Thank you ahead of time for any and all suggestions!
 
D

Dave Peterson

something like:

myPath = activeworkbook.path & "\"
or
myPath = Thisworkbook.path & "\"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top