Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Using Macro to Save Copy of File to New Location

I'm trying to record, and modify the code of, a macro that will be used to
save a file to a new location using a different file type. The problem I'm
having is that the macro now uses the recorded file name for every file that
is copied, regardless of the original file name. The "save as" procedure I'm
doing is to allow the user to click a custom toolbar button in any file to
save that file to a specific location, in the CSV format, while preserving
the original file's name.

Is there code available to preserve the original file name while changing
the file format for any file I choose to save?

Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Using Macro to Save Copy of File to New Location

I'd do something like:

Option Explicit

Sub testme01()
Dim wks As Worksheet
Dim myName As String

With ActiveWorkbook
myName = .Name
If Right(LCase(myName), 4) = ".xls" Then
myName = Left(myName, Len(myName) - 4)
End If
Set wks = .ActiveSheet
End With

wks.Copy 'to a new workbook

With ActiveSheet.Parent 'that new workbook
'just overwrite any existing file
'and don't show the warning message
Application.DisplayAlerts = False

'use your favorite folder!
.SaveAs Filename:="C:\temp\" & myName & ".csv", FileFormat:=xlCSV
Application.DisplayAlerts = True
.Close savechanges:=False
End With

End Sub


Chris Z wrote:

I'm trying to record, and modify the code of, a macro that will be used to
save a file to a new location using a different file type. The problem I'm
having is that the macro now uses the recorded file name for every file that
is copied, regardless of the original file name. The "save as" procedure I'm
doing is to allow the user to click a custom toolbar button in any file to
save that file to a specific location, in the CSV format, while preserving
the original file's name.

Is there code available to preserve the original file name while changing
the file format for any file I choose to save?

Thank you!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Using Macro to Save Copy of File to New Location

I finally got the time to try this and it worked great - thank you!

"Dave Peterson" wrote:

I'd do something like:

Option Explicit

Sub testme01()
Dim wks As Worksheet
Dim myName As String

With ActiveWorkbook
myName = .Name
If Right(LCase(myName), 4) = ".xls" Then
myName = Left(myName, Len(myName) - 4)
End If
Set wks = .ActiveSheet
End With

wks.Copy 'to a new workbook

With ActiveSheet.Parent 'that new workbook
'just overwrite any existing file
'and don't show the warning message
Application.DisplayAlerts = False

'use your favorite folder!
.SaveAs Filename:="C:\temp\" & myName & ".csv", FileFormat:=xlCSV
Application.DisplayAlerts = True
.Close savechanges:=False
End With

End Sub


Chris Z wrote:

I'm trying to record, and modify the code of, a macro that will be used to
save a file to a new location using a different file type. The problem I'm
having is that the macro now uses the recorded file name for every file that
is copied, regardless of the original file name. The "save as" procedure I'm
doing is to allow the user to click a custom toolbar button in any file to
save that file to a specific location, in the CSV format, while preserving
the original file's name.

Is there code available to preserve the original file name while changing
the file format for any file I choose to save?

Thank you!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Using Macro to Save Copy of File to New Location

Glad it worked ok.

Chris Z wrote:

I finally got the time to try this and it worked great - thank you!

"Dave Peterson" wrote:

I'd do something like:

Option Explicit

Sub testme01()
Dim wks As Worksheet
Dim myName As String

With ActiveWorkbook
myName = .Name
If Right(LCase(myName), 4) = ".xls" Then
myName = Left(myName, Len(myName) - 4)
End If
Set wks = .ActiveSheet
End With

wks.Copy 'to a new workbook

With ActiveSheet.Parent 'that new workbook
'just overwrite any existing file
'and don't show the warning message
Application.DisplayAlerts = False

'use your favorite folder!
.SaveAs Filename:="C:\temp\" & myName & ".csv", FileFormat:=xlCSV
Application.DisplayAlerts = True
.Close savechanges:=False
End With

End Sub


Chris Z wrote:

I'm trying to record, and modify the code of, a macro that will be used to
save a file to a new location using a different file type. The problem I'm
having is that the macro now uses the recorded file name for every file that
is copied, regardless of the original file name. The "save as" procedure I'm
doing is to allow the user to click a custom toolbar button in any file to
save that file to a specific location, in the CSV format, while preserving
the original file's name.

Is there code available to preserve the original file name while changing
the file format for any file I choose to save?

Thank you!


--

Dave Peterson


--

Dave Peterson
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
Macro to save a file with ref to a tick box Ozzie via OfficeKB.com Excel Discussion (Misc queries) 4 January 31st 06 02:39 PM
macro save a workbook whilst increasing file no shrek Excel Worksheet Functions 0 November 10th 05 02:40 PM
copy excell file to a CSV file and than to Notepad need to know bob Excel Discussion (Misc queries) 0 August 23rd 05 07:27 PM
save original data after macro is run again MINAL ZUNKE New Users to Excel 3 July 7th 05 12:48 PM
How do I save a copy of an excel file without the formulas? Saving Excel File without Formula Excel Worksheet Functions 1 February 14th 05 08:55 PM


All times are GMT +1. The time now is 07:57 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"