Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Save As selection in Active Sheet

Hi,
I need to Save As a new file only a selected range (it changes all the
time), right now it saves the whole sheet. How can I save only the selection?
Thanks in advance
--
gaba :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save As selection in Active Sheet

Create a new workbook (with a single sheet???).

Copy the range to that new workbook's sheet.
Save that new workbook.

gaba wrote:

Hi,
I need to Save As a new file only a selected range (it changes all the
time), right now it saves the whole sheet. How can I save only the selection?
Thanks in advance
--
gaba :)


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Save As selection in Active Sheet

Dave, Thanks for your answer. I was looking to do it through code, just one
click...
So far, I got this working.
I was curious to see if there was a way to save just the selection.

Sub SaveFile_As()

'Save Filename As
'needs to copy all information to new workbook, close this one without
saving = READ ONLY

Dim NewName As Variant

NameAk = "e1 Temperature Log" & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
If Dir(NewName) < "" Then
Select Case MsgBox("File Exists. Overwrite ?", vbYesNoCancel +
vbQuestion)
Case vbYes
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
Case vbNo
Do
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")
If NewName = False Then Exit Sub
Loop Until Dir(NewName) = ""
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Case Else
Exit Sub
End Select
Else
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End If
End If

Range("A2").Select

End Sub

--
gaba :)


"Dave Peterson" wrote:

Create a new workbook (with a single sheet???).

Copy the range to that new workbook's sheet.
Save that new workbook.

gaba wrote:

Hi,
I need to Save As a new file only a selected range (it changes all the
time), right now it saves the whole sheet. How can I save only the selection?
Thanks in advance
--
gaba :)


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save As selection in Active Sheet

One way:

Option Explicit
Sub SaveFile_As2()

'Save Filename As
'needs to copy all information to new workbook,
'close this one without saving = READ ONLY

Dim NewName As Variant
Dim RngToCopy As Range
Dim newWks As Worksheet
Dim NameAk As String

With ActiveSheet
Set RngToCopy = Selection
End With

NameAk = "e1 Temperature Log" & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
'create a single sheet workbook and use sheet1
Set newWks = Workbooks.Add(1).Worksheets(1)
RngToCopy.Copy _
Destination:=newWks.Range("a1")
Application.DisplayAlerts = False
newWks.Parent.SaveAs Filename:=NewName, _
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
newWks.Parent.Close savechanges:=False
End If
End Sub

I was kind of confused at why you were saving the original workbook to start,
though.

And this just overwrites any existing file.




gaba wrote:

Dave, Thanks for your answer. I was looking to do it through code, just one
click...
So far, I got this working.
I was curious to see if there was a way to save just the selection.

Sub SaveFile_As()

'Save Filename As
'needs to copy all information to new workbook, close this one without
saving = READ ONLY

Dim NewName As Variant

NameAk = "e1 Temperature Log" & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
If Dir(NewName) < "" Then
Select Case MsgBox("File Exists. Overwrite ?", vbYesNoCancel +
vbQuestion)
Case vbYes
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
Case vbNo
Do
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")
If NewName = False Then Exit Sub
Loop Until Dir(NewName) = ""
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Case Else
Exit Sub
End Select
Else
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End If
End If

Range("A2").Select

End Sub

--
gaba :)

"Dave Peterson" wrote:

Create a new workbook (with a single sheet???).

Copy the range to that new workbook's sheet.
Save that new workbook.

gaba wrote:

Hi,
I need to Save As a new file only a selected range (it changes all the
time), right now it saves the whole sheet. How can I save only the selection?
Thanks in advance
--
gaba :)


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Save As selection in Active Sheet

Dave,
Thanks a million. I'll give it a try right now.
--
gaba :)


"Dave Peterson" wrote:

One way:

Option Explicit
Sub SaveFile_As2()

'Save Filename As
'needs to copy all information to new workbook,
'close this one without saving = READ ONLY

Dim NewName As Variant
Dim RngToCopy As Range
Dim newWks As Worksheet
Dim NameAk As String

With ActiveSheet
Set RngToCopy = Selection
End With

NameAk = "e1 Temperature Log" & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
'create a single sheet workbook and use sheet1
Set newWks = Workbooks.Add(1).Worksheets(1)
RngToCopy.Copy _
Destination:=newWks.Range("a1")
Application.DisplayAlerts = False
newWks.Parent.SaveAs Filename:=NewName, _
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
newWks.Parent.Close savechanges:=False
End If
End Sub

I was kind of confused at why you were saving the original workbook to start,
though.

And this just overwrites any existing file.




gaba wrote:

Dave, Thanks for your answer. I was looking to do it through code, just one
click...
So far, I got this working.
I was curious to see if there was a way to save just the selection.

Sub SaveFile_As()

'Save Filename As
'needs to copy all information to new workbook, close this one without
saving = READ ONLY

Dim NewName As Variant

NameAk = "e1 Temperature Log" & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
If Dir(NewName) < "" Then
Select Case MsgBox("File Exists. Overwrite ?", vbYesNoCancel +
vbQuestion)
Case vbYes
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
Case vbNo
Do
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")
If NewName = False Then Exit Sub
Loop Until Dir(NewName) = ""
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName,
FileFormat:=xlWorkbookNormal
Case Else
Exit Sub
End Select
Else
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NewName, FileFormat:=xlWorkbookNormal
End If
End If

Range("A2").Select

End Sub

--
gaba :)

"Dave Peterson" wrote:

Create a new workbook (with a single sheet???).

Copy the range to that new workbook's sheet.
Save that new workbook.

gaba wrote:

Hi,
I need to Save As a new file only a selected range (it changes all the
time), right now it saves the whole sheet. How can I save only the selection?
Thanks in advance
--
gaba :)

--

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
save only active sheet Button. tim Excel Discussion (Misc queries) 7 May 23rd 08 11:27 PM
save active sheet VilMarci Excel Programming 6 May 17th 05 01:03 PM
Cell selection in non-active sheet Otto Moehrbach[_6_] Excel Programming 1 July 16th 04 05:16 PM
Looping thru the active selection No Name Excel Programming 2 June 4th 04 08:09 PM
Determining the Selection on a non-active Sheet? Jim S.[_4_] Excel Programming 2 April 17th 04 03:59 AM


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