Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Create new book..paste data..save..close

Hi all
Code below

Trying to create a new workbook paste some data to the new book
save and close.

Debug comes back here :

'===============================================
With wsSummary
Set cRange = .Application.Workbooks("lsr_template.xls") _
.Worksheets("Summary").Range("C2:G" & lngRows)
End With
'===============================================

I've tried a couple variations on this
Keeps bombing on me.

Thanks much
-goss

Full Code:

Sub lsr_WriteItOut()
'Get_Rows is UDF
'Globals: wbBook, wsData, wsFormulas, wsHeader, rnFormula

Dim wsSummary As Worksheet
Dim cellRef As Variant
Dim wbNew As Workbook
Dim newRange As Range
Dim cRange As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Set wbBook = ThisWorkbook

With wbBook
Set wsSummary = .Worksheets("Summary")
End With

With wsSummary
cellRef = .Range("H2").Value
End With

Set wbNew = Application.Workbooks.Add

With wbNew
.SaveAs "c:\lsr\lsr" & cellRef & ".xls"
.Sheets("Sheet1").Name = "Data"
End With

With wsSummary
Set cRange = .Application.Workbooks("lsr_template.xls") _
.Worksheets("Summary").Range("C2:G" & lngRows)
End With

With wbNew
Set newRange = .Application.Workbooks _
("lsr" & cellRef & ".xls") _
.Worksheets("Data").Range("A1")
End With

newRange.Value = cRange.Value

With wbNew
.Save
.Close
End With

'Clean Up / Reset
Set wbBook = Nothing
Set wbNew = Nothing
Set cRange = Nothing
Set newRange = Nothing

Set wsSummary = Nothing
Set copyfrRange = Nothing
Set copytoRange = Nothing

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Create new book..paste data..save..close

Because you have already set wsSummary you should be able to use just:

With wsSummary
Set cRange = .Range("C2:G" & lngRows)
End With

However you haven't set lngRows. You need to set lngRows first otherwise
it is 0 and this will cause an error.

Hope this helps
Rowan

wrote:
Hi all
Code below

Trying to create a new workbook paste some data to the new book
save and close.

Debug comes back here :

'===============================================
With wsSummary
Set cRange = .Application.Workbooks("lsr_template.xls") _
.Worksheets("Summary").Range("C2:G" & lngRows)
End With
'===============================================

I've tried a couple variations on this
Keeps bombing on me.

Thanks much
-goss

Full Code:

Sub lsr_WriteItOut()
'Get_Rows is UDF
'Globals: wbBook, wsData, wsFormulas, wsHeader, rnFormula

Dim wsSummary As Worksheet
Dim cellRef As Variant
Dim wbNew As Workbook
Dim newRange As Range
Dim cRange As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Set wbBook = ThisWorkbook

With wbBook
Set wsSummary = .Worksheets("Summary")
End With

With wsSummary
cellRef = .Range("H2").Value
End With

Set wbNew = Application.Workbooks.Add

With wbNew
.SaveAs "c:\lsr\lsr" & cellRef & ".xls"
.Sheets("Sheet1").Name = "Data"
End With

With wsSummary
Set cRange = .Application.Workbooks("lsr_template.xls") _
.Worksheets("Summary").Range("C2:G" & lngRows)
End With

With wbNew
Set newRange = .Application.Workbooks _
("lsr" & cellRef & ".xls") _
.Worksheets("Data").Range("A1")
End With

newRange.Value = cRange.Value

With wbNew
.Save
.Close
End With

'Clean Up / Reset
Set wbBook = Nothing
Set wbNew = Nothing
Set cRange = Nothing
Set newRange = Nothing

Set wsSummary = Nothing
Set copyfrRange = Nothing
Set copytoRange = Nothing

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub

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
Create a template, on close, save those cells into another workshe kangasnat Excel Worksheet Functions 1 March 5th 07 05:47 PM
create chart /table excel-save, close & reopen colors change? Why Anne Charts and Charting in Excel 1 July 4th 06 09:16 PM
I wish automate a cut and paste of data from one work book to ano Ian Anderson Excel Worksheet Functions 2 May 28th 06 08:28 AM
Open book, check for macros, close book Robin Hammond[_2_] Excel Programming 5 March 31st 05 06:09 PM
Copy and paste ranges from a close book using Validation stakar[_19_] Excel Programming 0 June 24th 04 02:37 PM


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