PC Review


Reply
Thread Tools Rate Thread

Adding New Sheets

 
 
Len
Guest
Posts: n/a
 
      15th Jul 2010
Hi,

After few attempts, the following codes fails to add new sheets and
rename its sheet to this workbook after copying worksheet from each
excel file under MPV folder

Dim i%, SheetArg$()
Dim sPath As String
Dim sFile As Variant
Dim oSht As Integer
Dim ShtFile As String

Windows("ABC.xls").Activate
sPath = "D:\My Documents\MPV\"
sFile = Dir(sPath & "*.xls", vbNormal)
Workbooks.Open Filename:=sPath & sFile
Do While sFile <> ""
oSht = Worksheets.Count
Workbooks(sFile).Sheets(1).Copy
Before:=Workbooks("ABC.xls").Sheets(oSht)
ShtFile = Left(sFile, InStrRev(sFile, ".") - 3)
ActiveSheet.Name = ShtFile
oSht = oSht + 1
Workbooks(sFile).Close SaveChanges:=False
sFile = Dir()
Loop

Any help will be appreciated and thanks in advance


Regards
Len
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jul 2010
You could try:

Dim i%, SheetArg$()
Dim sPath As String
Dim sFile As Variant
Dim oSht As Integer
Dim ShtFile As String

Windows("ABC.xls").Activate
oSht = Worksheets.Count

sPath = "D:\My Documents\MPV\"
sFile = Dir(sPath & "*.xls", vbNormal)

Do While sFile <> ""
Workbooks.Open Filename:=sPath & sFile
Workbooks(sFile).Sheets(1).Copy _
Before:=Workbooks("ABC.xls").Sheets(oSht)
ShtFile = Left(sFile, InStrRev(sFile, ".") - 3)
ActiveSheet.Name = ShtFile
oSht = oSht + 1
Workbooks(sFile).Close SaveChanges:=False
sFile = Dir()
Loop


Did you really mean to use Before:= and not After:=????

On 07/15/2010 01:57, Len wrote:
> Dim i%, SheetArg$()
> Dim sPath As String
> Dim sFile As Variant
> Dim oSht As Integer
> Dim ShtFile As String
>
> Windows("ABC.xls").Activate
> sPath = "D:\My Documents\MPV\"
> sFile = Dir(sPath& "*.xls", vbNormal)
> Workbooks.Open Filename:=sPath& sFile
> Do While sFile<> ""
> oSht = Worksheets.Count
> Workbooks(sFile).Sheets(1).Copy
> Before:=Workbooks("ABC.xls").Sheets(oSht)
> ShtFile = Left(sFile, InStrRev(sFile, ".") - 3)
> ActiveSheet.Name = ShtFile
> oSht = oSht + 1
> Workbooks(sFile).Close SaveChanges:=False
> sFile = Dir()
> Loop


--
Dave Peterson
 
Reply With Quote
 
Len
Guest
Posts: n/a
 
      16th Jul 2010
Hi Dave,


Thanks for your reply and your codes
Yes, I should use "After:=" and it works perfectly


Regards
Len

 
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
adding sheets ganga Microsoft Excel Misc 2 16th Jun 2009 03:40 AM
Adding sheets Ramesh Microsoft Excel Discussion 2 22nd Jul 2005 05:32 AM
adding from all sheets Treeskier Microsoft Excel Discussion 12 18th Jun 2004 11:32 PM
Adding Sheets Treeskier Microsoft Excel Discussion 5 18th Jun 2004 11:30 PM
adding sheets together Andrea Microsoft Excel Programming 3 7th Nov 2003 06:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 AM.