简体   繁体   中英

Save Excel table in current folder

I want to save my current table as a text file in the same folder as the current workbook (that is open).

I use this code:

ActiveWorkbook.SaveAs ThisWorkbook.path & "\" & filename

For some reason it save the text file in the same folder as my personal.xlsb.

I use Office 2010

If this is not possible to do easily then maybe one can force Excel to open a browse window where I can pick where I want the file saved.

ThisWorkbook points to the location where the code is written. In your case personal.xlsb.

If you want to save the table in the same directory as the active workbook, use ActiveWorkbook.path instead.

You may try this

ChDir "C:\yourfolder" ActiveWorkbook.SaveAs Filename:= _ "c:\yourfolder" & filename & ".txt", FileFormat:=xlText, _

In this example I have created a folder name "yourfolder" in my C drive. The created text file will save in C\yourfolder\filenane.txt

Hope this is helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM