Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Save only a range from an excel file to another

Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)

Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.

I hope you understand what i need to do :) thanks in advance to every
one.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Save only a range from an excel file to another

Hi

See this mail macro for the code
Delete the mail stuff
http://www.rondebruin.nl/mail/folder1/mail4.htm

If you need more help post back



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


wrote in message ...
Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)

Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.

I hope you understand what i need to do :) thanks in advance to every
one.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Save only a range from an excel file to another

Hello Ron Thanks to reply! You code seems work but doesn't save the
file this i the code that i keep do you see any error?

Sub Mail_Range()


'Working in 2000-2007
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long

Set Source = Nothing
On Error Resume Next
Set Source = Range("A1:H100").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected,
please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)

Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With

TempFilePath = "c:\temp\"
TempFileName = "Test"

If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsx": FileFormatNum = 51
End If

With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error GoTo 0
.Close SaveChanges:=False
End With

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


On 5 dec, 16:21, "Ron de Bruin" wrote:
Hi

See this mail macro for the code
Delete the mail stuffhttp://www.rondebruin.nl/mail/folder1/mail4.htm

If you need more help post back

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm



wrote in ...
Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)


Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.


I hope you understand what i need to do :) thanks in advance to every
one.- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Save only a range from an excel file to another

Hello Ron I just find the error, i deleted the last part

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

and it's work!!

Thanks a lot! if you are from amsterdam i will pay a beertje :D

On 5 Dic, 17:09, wrote:
Hello Ron Thanks to reply! You code seems work but doesn't save the
file this i the code that i keep do you see any error?

Sub Mail_Range()

'Working in 2000-2007
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long

Set Source = Nothing
On Error Resume Next
Set Source = Range("A1:H100").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected,
please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)

Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With

TempFilePath = "c:\temp\"
TempFileName = "Test"

If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsx": FileFormatNum = 51
End If

With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error GoTo 0
.Close SaveChanges:=False
End With

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

On 5 dec, 16:21, "Ron de Bruin" wrote:



Hi


See this mail macro for the code
Delete the mail stuffhttp://www.rondebruin.nl/mail/folder1/mail4.htm


If you need more help post back


--


Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm


wrote in ...
Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)


Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.


I hope you understand what i need to do :) thanks in advance to every
one.- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -- Nascondi testo tra virgolette -


- Mostra testo tra virgolette -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Save only a range from an excel file to another

It save the file mail it and delete it

Delete this line

Kill TempFilePath & TempFileName & FileExtStr


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


wrote in message ...
Hello Ron Thanks to reply! You code seems work but doesn't save the
file this i the code that i keep do you see any error?

Sub Mail_Range()


'Working in 2000-2007
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long

Set Source = Nothing
On Error Resume Next
Set Source = Range("A1:H100").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected,
please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)

Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With

TempFilePath = "c:\temp\"
TempFileName = "Test"

If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsx": FileFormatNum = 51
End If

With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error GoTo 0
.Close SaveChanges:=False
End With

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


On 5 dec, 16:21, "Ron de Bruin" wrote:
Hi

See this mail macro for the code
Delete the mail stuffhttp://www.rondebruin.nl/mail/folder1/mail4.htm

If you need more help post back

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm



wrote in ...
Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)


Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.


I hope you understand what i need to do :) thanks in advance to every
one.- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Save only a range from an excel file to another

You are welcome

Kill TempFilePath & TempFileName & FileExtStr

Only delete this line

Thanks a lot! if you are from amsterdam

One hour with the car


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


wrote in message ...
Hello Ron I just find the error, i deleted the last part

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

and it's work!!

Thanks a lot! if you are from amsterdam i will pay a beertje :D

On 5 Dic, 17:09, wrote:
Hello Ron Thanks to reply! You code seems work but doesn't save the
file this i the code that i keep do you see any error?

Sub Mail_Range()

'Working in 2000-2007
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long

Set Source = Nothing
On Error Resume Next
Set Source = Range("A1:H100").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected,
please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)

Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With

TempFilePath = "c:\temp\"
TempFileName = "Test"

If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsx": FileFormatNum = 51
End If

With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error GoTo 0
.Close SaveChanges:=False
End With

Kill TempFilePath & TempFileName & FileExtStr

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

On 5 dec, 16:21, "Ron de Bruin" wrote:



Hi


See this mail macro for the code
Delete the mail stuffhttp://www.rondebruin.nl/mail/folder1/mail4.htm


If you need more help post back


--


Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm


wrote in ...
Hello,
I have this problem, i want create a macro that create a new file with
a Range (Ex A1:B56)


Ex.
In the file X i have 4 sheets i want a macro that take all the data
From The sheet1 in the range A1:B56 and save this range as file Y.


I hope you understand what i need to do :) thanks in advance to every
one.- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -- Nascondi testo tra virgolette -


- Mostra testo tra virgolette -


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
How can I save a Range in Excel to a Word File? Martin Fishlock Excel Programming 0 January 5th 07 07:38 AM
Save a Range on a Workbook as a CSV File Connie Excel Discussion (Misc queries) 2 October 20th 06 03:42 PM
Save a selected range to a new text file in excel [email protected] Excel Discussion (Misc queries) 0 October 3rd 06 11:27 PM
File Save As -Selected Range Sprint54 Excel Discussion (Misc queries) 1 February 8th 06 02:28 AM
Excel marcos firing on file save as but not file save Andy Excel Programming 1 August 3rd 04 10:34 AM


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