Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't figure out how to open each file

I'm working on a macro to open a series of files in the same directory,
copy the page, then paste each page into a corresponding sheet with a
corresponding name in a different workbook.

'Change to appropriate method and file
Set wbPIP = Workbooks("PIP Test1.xls")
frmYrQtrInput.Show
sDirMod = "H:\AllDocs\CFSR PIP DD\SFY " & sCurYr & Space(1) & _
"Q" & sCurQtr & "\Records Mod\"
sFName = Dir(sDirMod)
lFileCt = 0

Do Until sFName = ""
Set wb = Workbooks(sFName) <-----SUBSCRIPT OUT OF RANGE

wb(sFName).Open
Selection.CurrentRegion.Select
Selection.Copy

sShtName = Left(sFName, Len(sFName) - 7)
sShtName = sShtName & "Records"
wbPIP.Activate
wbPIP.Worksheets(sShtName).Activate
'Range("b2").Select 'TEST
Selection.CurrentRegion.Select
Selection.Clear
Range("A1").Select
Selection.Paste

lFileCt = lFileCt + 1
sFName = Dir()
Loop
MsgBox (lFileCt & " files were copied to the PIP spreadsheet."),
vbOKOnly

Application.ScreenUpdating = True
End Sub

Help! And thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Can't figure out how to open each file

you have to open it first:

Do Until sFName = ""
Set wb = Workbooks.Open(sDirMod & sFName)

--
Regards,
Tom Ogilvy



"davegb" wrote:

I'm working on a macro to open a series of files in the same directory,
copy the page, then paste each page into a corresponding sheet with a
corresponding name in a different workbook.

'Change to appropriate method and file
Set wbPIP = Workbooks("PIP Test1.xls")
frmYrQtrInput.Show
sDirMod = "H:\AllDocs\CFSR PIP DD\SFY " & sCurYr & Space(1) & _
"Q" & sCurQtr & "\Records Mod\"
sFName = Dir(sDirMod)
lFileCt = 0

Do Until sFName = ""
Set wb = Workbooks(sFName) <-----SUBSCRIPT OUT OF RANGE

wb(sFName).Open
Selection.CurrentRegion.Select
Selection.Copy

sShtName = Left(sFName, Len(sFName) - 7)
sShtName = sShtName & "Records"
wbPIP.Activate
wbPIP.Worksheets(sShtName).Activate
'Range("b2").Select 'TEST
Selection.CurrentRegion.Select
Selection.Clear
Range("A1").Select
Selection.Paste

lFileCt = lFileCt + 1
sFName = Dir()
Loop
MsgBox (lFileCt & " files were copied to the PIP spreadsheet."),
vbOKOnly

Application.ScreenUpdating = True
End Sub

Help! And thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't figure out how to open each file


Tom Ogilvy wrote:
you have to open it first:

Do Until sFName = ""
Set wb = Workbooks.Open(sDirMod & sFName)

--
Regards,
Tom Ogilvy


As always, thanks Tom!



"davegb" wrote:

I'm working on a macro to open a series of files in the same directory,
copy the page, then paste each page into a corresponding sheet with a
corresponding name in a different workbook.

'Change to appropriate method and file
Set wbPIP = Workbooks("PIP Test1.xls")
frmYrQtrInput.Show
sDirMod = "H:\AllDocs\CFSR PIP DD\SFY " & sCurYr & Space(1) & _
"Q" & sCurQtr & "\Records Mod\"
sFName = Dir(sDirMod)
lFileCt = 0

Do Until sFName = ""
Set wb = Workbooks(sFName) <-----SUBSCRIPT OUT OF RANGE

wb(sFName).Open
Selection.CurrentRegion.Select
Selection.Copy

sShtName = Left(sFName, Len(sFName) - 7)
sShtName = sShtName & "Records"
wbPIP.Activate
wbPIP.Worksheets(sShtName).Activate
'Range("b2").Select 'TEST
Selection.CurrentRegion.Select
Selection.Clear
Range("A1").Select
Selection.Paste

lFileCt = lFileCt + 1
sFName = Dir()
Loop
MsgBox (lFileCt & " files were copied to the PIP spreadsheet."),
vbOKOnly

Application.ScreenUpdating = True
End Sub

Help! And thanks.



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
how do i maintain same figure with formula link to another file by amp Excel Discussion (Misc queries) 1 September 30th 06 08:15 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Code to Save As, then Open - can't figure it out! [email protected] Excel Discussion (Misc queries) 0 May 25th 06 09:18 PM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
HOW TO CONVERT A FIGURE INTO TEXT IN EXCEL FILE. PLEASE LET US KN ASHOKAN NAMBIAR Excel Discussion (Misc queries) 3 October 16th 05 11:55 AM


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