LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Create WB, create new Sht, paste data. (Macro not working)

The code below should create a new workbook, add a sheet, Open an existing
WB, copy data then past the data onto the new sheet in the new WB. But
somewhere it is failing and I do not see why.
When I read the macro I see it as top down activity, but I am obviously
missing something somewhere.

Creates the new workbook (Ok, sNewItem & some text)
Opens a WB to copy data from (Ok, "Template IAR Sheet1.xlsx")
Selects the data (Ok, Cells.Select)
copies Selection (Ok, Selection.Copy)
Create new Sht (Fails)
Paste data on new Sht (Fails, because new Sht fails)
ActiveWorkbook.Close (Fails to close "Template IAR Sheet1.xlsx")
Note: passwords in macro are nothing, they are generic values for testing

'============
Sub CreateNewWorkbooks()
Application.ScreenUpdating = False

sNewItem = InputBox(prompt:="Enter Entire Path for Folder/File Location!")
On Error GoTo EndIt
Set wb = ActiveWorkbook
Dim wkSheet As Worksheet
For i = 1 To Worksheets.Count
Sheets(i).Activate
With ActiveSheet
sSheetName = ActiveSheet.Name
If ActiveSheet.Name = "Sheet1" Then
GoTo EndIt
End If
Sheets(sSheetName).Select
Sheets(sSheetName).Copy
ActiveWorkbook.SaveAs Filename:= _
sNewItem & "\Template ISO " & sSheetName & " Audit
mm.dd.yy.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False,
WriteResPassword:="2000"
'open "Template IAR Sheet1.xlsx" and create copy of sheet1
Workbooks.Open Filename:= _
"M:\Qadocs\ISO DOCS\ISO Audits\Templates\Template IAR
Sheet1.xlsx", _
WriteResPassword:="2000"
Windows("Template IAR Sheet1.xlsx").Activate
Cells.Select
Selection.Copy
'Select new workbook, create new sheet and paste new cells
Windows(sNewItem & "\Template ISO " & sSheetName & " Audit
mm.dd.yy.xlsx").Activate
Sheets.Add After:=Sheets(Sheets.Count)
Cells.Select
ActiveSheet.Paste
Workbooks("M:\Qadocs\ISO DOCS\ISO Audits\Templates\Template IAR
Sheet1.xlsx").Activate
ActiveWorkbook.Close
Windows(wb.Name).Activate
End With
Next i
EndIt:
Application.ScreenUpdating = True
End Sub
'============

--
Regards

Rick
XP Pro
Office 2007

 
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
1 Create a macro to Copy & paste certain data to another sheet Lin1981 Excel Discussion (Misc queries) 1 November 6th 08 11:56 PM
How to create a macro which performs a copy-and-paste task every 5mins after data is refreshed from web page? ­»´ä®a©~¸Ë­× Excel Worksheet Functions 0 December 5th 06 08:57 AM
create Macro €“ select data, sort by acc no., yr, part no, create P Johnny Excel Programming 0 November 22nd 06 03:18 PM
Macro cut and paste quits, can't re-create NM Burton Excel Programming 1 November 24th 04 06:04 PM
create a macro to copy/paste cell data joshua.v Excel Programming 1 September 14th 04 04:42 PM


All times are GMT +1. The time now is 06:30 AM.

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

About Us

"It's about Microsoft Excel"