PC Review


Reply
Thread Tools Rate Thread

Code does as instructed, but creates and saves a Book1

 
 
Pierre
Guest
Posts: n/a
 
      15th Jul 2010
Am using this code to save the active sheet in a new book called
"Monthly_Inventory" in compatability mode. It works fine, but it also
adds another workbook to the directory. .Book1, or Book2, etc. Can
anyone look at the code and determine which line is causing this
additional workbook to be created?
Many thanks in advance.
Pierre

Sub Create_New_Workbook_Inventory()
'Save with formatting Macro
'
Sheets("Sheet1").Select
Cells.Select
ActiveSheet.Copy
Set newbk = ActiveWorkbook
newbk.ActiveSheet.Cells.Copy
newbk.ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

InitialName = ("Monthly_Inventory") & ".xls"
FName = Application.GetSaveAsFilename(InitialFileName:=InitialName, _
fileFilter:="Excel Files (*.xls), *.xls")

ActiveWorkbook.SaveAs , FileFormat:=xlExcel8
newbk.SaveAs Filename:=FName

End Sub

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jul 2010
You have a pair of lines here:

ActiveWorkbook.SaveAs , FileFormat:=xlExcel8
newbk.SaveAs Filename:=FName


The top one doesn't specify the file name, so excel will use what it likes
(book1, book2, ...)

Maybe deleting the first line and using:

newbk.SaveAs Filename:=FName, fileformat:=xlexcel8

would work ok.

On 07/15/2010 15:05, Pierre wrote:
> Am using this code to save the active sheet in a new book called
> "Monthly_Inventory" in compatability mode. It works fine, but it also
> adds another workbook to the directory. .Book1, or Book2, etc. Can
> anyone look at the code and determine which line is causing this
> additional workbook to be created?
> Many thanks in advance.
> Pierre
>
> Sub Create_New_Workbook_Inventory()
> 'Save with formatting Macro
> '
> Sheets("Sheet1").Select
> Cells.Select
> ActiveSheet.Copy
> Set newbk = ActiveWorkbook
> newbk.ActiveSheet.Cells.Copy
> newbk.ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
> Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
> SkipBlanks:=False, Transpose:=False
>
> InitialName = ("Monthly_Inventory")& ".xls"
> FName = Application.GetSaveAsFilename(InitialFileName:=InitialName, _
> fileFilter:="Excel Files (*.xls), *.xls")
>
> ActiveWorkbook.SaveAs , FileFormat:=xlExcel8
> newbk.SaveAs Filename:=FName
>
> End Sub
>


--
Dave Peterson
 
Reply With Quote
 
Pierre
Guest
Posts: n/a
 
      16th Jul 2010
Dave, many thanks, yet again.

Pierre

On Jul 15, 5:04*pm, Dave Peterson <peter...@XSPAMverizon.net> wrote:
> You have a pair of lines here:
>
> ActiveWorkbook.SaveAs , FileFormat:=xlExcel8
> newbk.SaveAs Filename:=FName
>
> The top one doesn't specify the file name, so excel will use what it likes
> (book1, book2, ...)
>
> Maybe deleting the first line and using:
>
> newbk.SaveAs Filename:=FName, fileformat:=xlexcel8
>
> would work ok.
>
> On 07/15/2010 15:05, Pierre wrote:
>
>
>
>
>
> > Am using this code to save the active sheet in a new book called
> > "Monthly_Inventory" in compatability mode. *It works fine, but it also
> > adds another workbook to the directory. *.Book1, or Book2, etc. *Can
> > anyone look at the code and determine which line is causing this
> > additional workbook to be created?
> > Many thanks in advance.
> > Pierre

>
> > Sub Create_New_Workbook_Inventory()
> > 'Save with formatting Macro
> > '
> > Sheets("Sheet1").Select
> > Cells.Select
> > ActiveSheet.Copy
> > Set newbk = ActiveWorkbook
> > newbk.ActiveSheet.Cells.Copy
> > newbk.ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
> > Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
> > * * * * *SkipBlanks:=False, Transpose:=False

>
> > InitialName = ("Monthly_Inventory")& *".xls"
> > FName = Application.GetSaveAsFilename(InitialFileName:=InitialName,_
> > * * fileFilter:="Excel Files (*.xls), *.xls")

>
> > ActiveWorkbook.SaveAs , FileFormat:=xlExcel8
> > newbk.SaveAs Filename:=FName

>
> > End Sub

>
> --
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to have code close an open email after it saves. DStrong Microsoft Outlook VBA Programming 5 4th Nov 2008 07:46 PM
Execute code from book1 of code from book2 =?Utf-8?B?Umljaw==?= Microsoft Excel Programming 4 5th Jun 2007 05:19 PM
How to create a template that creates and saves as sequencial num. =?Utf-8?B?VmlwZXI=?= Microsoft Excel Programming 4 7th Dec 2005 10:59 PM
Code for "Do Not Save" Book1 in visualbasic macro mike Microsoft Excel Worksheet Functions 3 28th Jun 2004 07:06 PM
IE to Book1, to book2, then close Book1.xls GotDebt Microsoft Excel Programming 3 5th Dec 2003 08:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.