Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Saving filename same as import filename

I have a macro that imports a txt file(test.txt) into an Excel spreadsheet and then I want to save this file with the same name as the txt file(test) obviously w/out the .txt. Any ideas? Thanks. Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Saving filename same as import filename

Activeworkbook.SaveAs Activeworkbook.Path & "\" & _
left(Activeworkbook.Filename, len(Activeworkbook.Filename)-4) & ".xls", _
fileformat:=xlWorkbookNormal

--
Regards,
Tom Ogilvy

"Matt" wrote in message
...
I have a macro that imports a txt file(test.txt) into an Excel spreadsheet

and then I want to save this file with the same name as the txt file(test)
obviously w/out the .txt. Any ideas? Thanks. Matt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Saving filename same as import filename


-----Original Message-----
I have a macro that imports a txt file(test.txt) into an

Excel spreadsheet and then I want to save this file with
the same name as the txt file(test) obviously w/out
the .txt. Any ideas? Thanks. Matt
.

Dim MyFileName As String

MyFileName = "Your Text File Name"

'use the following name (using the appropriate code)
'to import text file
MyFileName & ."txt"

ActiveWorkbook.SaveAs FileName:="C:\" & MyFileName
& ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Saving filename same as import filename


-----Original Message-----

-----Original Message-----
I have a macro that imports a txt file(test.txt) into an

Excel spreadsheet and then I want to save this file with
the same name as the txt file(test) obviously w/out
the .txt. Any ideas? Thanks. Matt
.

Dim MyFileName As String

MyFileName = "Your Text File Name"

'use the following name (using the appropriate code)
'to import text file
MyFileName & ."txt"

ActiveWorkbook.SaveAs FileName:="C:\" & MyFileName
& ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

.
Whoops that should be

MyFileName & ".txt"
Sorry about that..
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Saving filename same as import filename

I tried this code but I get an error that says Method 'SaveAs' of object '_Workbook' failed. I can't figure out what the problem is other than maybe it is naming the excel workbook the same as the text file it is importing. For example it is naming it test.txt.xls. Could this be a problem? fileToOpen is the name of the text file that I am importing. Thanks. Mat

ActiveWorkbook.SaveAs Filename:="H:\" & fileToOpen & ".xls", FileFormat:=xlNormal,
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
CreateBackup:=False
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving file using value in cell as the filename BCassedy Excel Worksheet Functions 3 July 7th 07 12:43 AM
Saving XLS workbook with set filename levertonfamily Excel Discussion (Misc queries) 0 November 16th 06 05:52 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Filename import CiceroCF Excel Discussion (Misc queries) 4 January 4th 06 01:54 PM
Saving Cell value as filename Kathy B Excel Programming 1 July 24th 03 10:59 PM


All times are GMT +1. The time now is 07:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"