PC Review


Reply
Thread Tools Rate Thread

copying sheet1 from different workbooks contained in a folder to myone and only destination workbook.

 
 
Jeff
Guest
Posts: n/a
 
      14th Apr 2009
Hi All,

Good day everyone. Can anyone help me? I have one workbook with
filename "Listing Excel Files in a Folder".
I was trying to create a macro in this workbook, which can open all
the excel files in a particular folder. Then copy the sheet with sheet
name "Pricebook Pages" from these excel files and paste it to the
different blank worksheets that i prepared in my workbook "Listing
Excel Files in a Folder".

The excel files in a folder are pricebooks of different customer. The
pricebook data is always in sheet1("Pricebook Pages").

Cheers.

Jeff
 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      14th Apr 2009
the code creates a dialog box to select the source folder and then opens
every XLS file in the folder and puts the sheet into the workbook where the
macro is located. I thought this was easier then to use you list of files in
the workbook.

Sub MakePriceBook()

Set objShell = CreateObject("Shell.Application")
Set fs = CreateObject("Scripting.FileSystemObject")


On Error Resume Next
Set objFolder = objShell.BrowseForFolder(&H0&, "Select Folder ", &H4001&)
On Error GoTo 0

If objFolder Is Nothing Then
MsgBox ("Cannot open directory - Exit Macro")
Exit Sub
End If

Set oFolderItem = objFolder.Items.Item
Folder = oFolderItem.Path

Folder = Folder & "/"

FName = Dir(Folder & "*.xls")
Do While FName <> ""
With ThisWorkbook
Set oldbk = Workbooks.Open(Filename:=Folder & FName)
oldbk.Sheets("Pricebook Pages").Copy _
after:=.Sheets(.Sheets.Count)
End With
ActiveSheet.Name = FName
oldbk.Close savechanges:=False
FName = Dir()
Loop
End Sub



"Jeff" wrote:

> Hi All,
>
> Good day everyone. Can anyone help me? I have one workbook with
> filename "Listing Excel Files in a Folder".
> I was trying to create a macro in this workbook, which can open all
> the excel files in a particular folder. Then copy the sheet with sheet
> name "Pricebook Pages" from these excel files and paste it to the
> different blank worksheets that i prepared in my workbook "Listing
> Excel Files in a Folder".
>
> The excel files in a folder are pricebooks of different customer. The
> pricebook data is always in sheet1("Pricebook Pages").
>
> Cheers.
>
> Jeff
>

 
Reply With Quote
 
Pc
Guest
Posts: n/a
 
      15th Apr 2009
Hi,

thanks I tried using this code for copying files from one folder to
another I get the subscript out of range error when it tries to execute the
code

oldbk.Sheets("Pricebook Pages").Copy _
after:=.Sheets(.Sheets.Count)

could you please help. Thanks.

Pc

"joel" wrote:

> the code creates a dialog box to select the source folder and then opens
> every XLS file in the folder and puts the sheet into the workbook where the
> macro is located. I thought this was easier then to use you list of files in
> the workbook.
>
> Sub MakePriceBook()
>
> Set objShell = CreateObject("Shell.Application")
> Set fs = CreateObject("Scripting.FileSystemObject")
>
>
> On Error Resume Next
> Set objFolder = objShell.BrowseForFolder(&H0&, "Select Folder ", &H4001&)
> On Error GoTo 0
>
> If objFolder Is Nothing Then
> MsgBox ("Cannot open directory - Exit Macro")
> Exit Sub
> End If
>
> Set oFolderItem = objFolder.Items.Item
> Folder = oFolderItem.Path
>
> Folder = Folder & "/"
>
> FName = Dir(Folder & "*.xls")
> Do While FName <> ""
> With ThisWorkbook
> Set oldbk = Workbooks.Open(Filename:=Folder & FName)
> oldbk.Sheets("Pricebook Pages").Copy _
> after:=.Sheets(.Sheets.Count)
> End With
> ActiveSheet.Name = FName
> oldbk.Close savechanges:=False
> FName = Dir()
> Loop
> End Sub
>
>
>
> "Jeff" wrote:
>
> > Hi All,
> >
> > Good day everyone. Can anyone help me? I have one workbook with
> > filename "Listing Excel Files in a Folder".
> > I was trying to create a macro in this workbook, which can open all
> > the excel files in a particular folder. Then copy the sheet with sheet
> > name "Pricebook Pages" from these excel files and paste it to the
> > different blank worksheets that i prepared in my workbook "Listing
> > Excel Files in a Folder".
> >
> > The excel files in a folder are pricebooks of different customer. The
> > pricebook data is always in sheet1("Pricebook Pages").
> >
> > Cheers.
> >
> > Jeff
> >

 
Reply With Quote
 
joel
Guest
Posts: n/a
 
      15th Apr 2009
When you get the error the two workbooks will be opened. go to the workbook
that doesn't have the macro (the one opened by the macro) and check the sheet
names. Make sure there is a sheet named "Pricebook Pages".

"Pc" wrote:

> Hi,
>
> thanks I tried using this code for copying files from one folder to
> another I get the subscript out of range error when it tries to execute the
> code
>
> oldbk.Sheets("Pricebook Pages").Copy _
> after:=.Sheets(.Sheets.Count)
>
> could you please help. Thanks.
>
> Pc
>
> "joel" wrote:
>
> > the code creates a dialog box to select the source folder and then opens
> > every XLS file in the folder and puts the sheet into the workbook where the
> > macro is located. I thought this was easier then to use you list of files in
> > the workbook.
> >
> > Sub MakePriceBook()
> >
> > Set objShell = CreateObject("Shell.Application")
> > Set fs = CreateObject("Scripting.FileSystemObject")
> >
> >
> > On Error Resume Next
> > Set objFolder = objShell.BrowseForFolder(&H0&, "Select Folder ", &H4001&)
> > On Error GoTo 0
> >
> > If objFolder Is Nothing Then
> > MsgBox ("Cannot open directory - Exit Macro")
> > Exit Sub
> > End If
> >
> > Set oFolderItem = objFolder.Items.Item
> > Folder = oFolderItem.Path
> >
> > Folder = Folder & "/"
> >
> > FName = Dir(Folder & "*.xls")
> > Do While FName <> ""
> > With ThisWorkbook
> > Set oldbk = Workbooks.Open(Filename:=Folder & FName)
> > oldbk.Sheets("Pricebook Pages").Copy _
> > after:=.Sheets(.Sheets.Count)
> > End With
> > ActiveSheet.Name = FName
> > oldbk.Close savechanges:=False
> > FName = Dir()
> > Loop
> > End Sub
> >
> >
> >
> > "Jeff" wrote:
> >
> > > Hi All,
> > >
> > > Good day everyone. Can anyone help me? I have one workbook with
> > > filename "Listing Excel Files in a Folder".
> > > I was trying to create a macro in this workbook, which can open all
> > > the excel files in a particular folder. Then copy the sheet with sheet
> > > name "Pricebook Pages" from these excel files and paste it to the
> > > different blank worksheets that i prepared in my workbook "Listing
> > > Excel Files in a Folder".
> > >
> > > The excel files in a folder are pricebooks of different customer. The
> > > pricebook data is always in sheet1("Pricebook Pages").
> > >
> > > Cheers.
> > >
> > > Jeff
> > >

 
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
Copying C drive makes destination folder invisible Ronny Windows XP Help 2 2nd Aug 2008 07:02 AM
Copying dada from multiple workbooks into 1 workbook Jasonm Microsoft Excel Programming 4 16th Dec 2007 03:30 AM
Copying Several Workbooks into one Workbook as Worksheets =?Utf-8?B?Qmx1ZV9DcnlzdGFs?= Microsoft Excel New Users 1 26th May 2005 02:19 PM
Excel Copying whole Sheets from mulitple workbooks, to a target workbook Allen Microsoft Excel Programming 5 15th Mar 2004 09:09 PM
copy sheet1 from all open workbooks to one workbook Mike Microsoft Excel Programming 2 31st Oct 2003 02:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:34 AM.