Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cant find sheet

Hi,

I am trying to populate one sheet with data from 120 other workbooks/sheets.
They all have the same template. When running the code below it cant find the
requested sheet. Is there a problem with my way of opening the file? I have
confirmed that the name exist and is correct.

Sub Upload()
Dim fs, f, s, fc, f1, f2

f2 = ThisWorkbook.Path

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfolder(f2 + "\files\")
Set fc = f.Files
For Each f1 In fc

Open f1 For Binary Access Read As #1
Sheets("Business Overview").Range("B4:c38").Copy
Windows("VB_work.xls").Activate
Sheets("temp").Range("h3").Paste
Workbooks(s).Close
Windows("VB_work.xls").Activate

Next

End Sub

/Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Cant find sheet

With Scripting and binary access you are reading the file in its "raw" form:
binary digits. This eliminates the ability for Excel to interpret it as an
Excel file. What you need to do instead is to get Excel to open it; my
recommendation for that is as follows:

Dim XLApp as Excel.Application, XLBook as Excel.Workbook
Set XLApp = New Excel.Application ' Opens a new Excel session (hidden)

f2 = ThisWorkbook.Path

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfolder(f2 + "\files\")
Set fc = f.Files
For Each f1 In fc
Set XLBook = XLApp.Workbooks.Open(f1) ' Opens the file in the hidden
Excel session - below use XLBook to refer to this workbook:

XLBook.Sheets("Business Overview").Range("B4:c38").Copy
' Unnecessary to activate the current book since the code is running
within it
Sheets("temp").Range("h3").Paste ' - so this pastes to the current
workbook
XLBook.Close False

Next

"Jim73" wrote:

Hi,

I am trying to populate one sheet with data from 120 other workbooks/sheets.
They all have the same template. When running the code below it cant find the
requested sheet. Is there a problem with my way of opening the file? I have
confirmed that the name exist and is correct.

Sub Upload()
Dim fs, f, s, fc, f1, f2

f2 = ThisWorkbook.Path

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfolder(f2 + "\files\")
Set fc = f.Files
For Each f1 In fc

Open f1 For Binary Access Read As #1
Sheets("Business Overview").Range("B4:c38").Copy
Windows("VB_work.xls").Activate
Sheets("temp").Range("h3").Paste
Workbooks(s).Close
Windows("VB_work.xls").Activate

Next

End Sub

/Jim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cant find sheet

Exactly what needed.

Thanks a lot,

"K Dales" wrote:

With Scripting and binary access you are reading the file in its "raw" form:
binary digits. This eliminates the ability for Excel to interpret it as an
Excel file. What you need to do instead is to get Excel to open it; my
recommendation for that is as follows:

Dim XLApp as Excel.Application, XLBook as Excel.Workbook
Set XLApp = New Excel.Application ' Opens a new Excel session (hidden)

f2 = ThisWorkbook.Path

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfolder(f2 + "\files\")
Set fc = f.Files
For Each f1 In fc
Set XLBook = XLApp.Workbooks.Open(f1) ' Opens the file in the hidden
Excel session - below use XLBook to refer to this workbook:

XLBook.Sheets("Business Overview").Range("B4:c38").Copy
' Unnecessary to activate the current book since the code is running
within it
Sheets("temp").Range("h3").Paste ' - so this pastes to the current
workbook
XLBook.Close False

Next

"Jim73" wrote:

Hi,

I am trying to populate one sheet with data from 120 other workbooks/sheets.
They all have the same template. When running the code below it cant find the
requested sheet. Is there a problem with my way of opening the file? I have
confirmed that the name exist and is correct.

Sub Upload()
Dim fs, f, s, fc, f1, f2

f2 = ThisWorkbook.Path

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfolder(f2 + "\files\")
Set fc = f.Files
For Each f1 In fc

Open f1 For Binary Access Read As #1
Sheets("Business Overview").Range("B4:c38").Copy
Windows("VB_work.xls").Activate
Sheets("temp").Range("h3").Paste
Workbooks(s).Close
Windows("VB_work.xls").Activate

Next

End Sub

/Jim

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 can find sheet on workbook have so many sheet ? Huy Nguyen Excel Worksheet Functions 1 November 22nd 07 08:45 AM
find last row in a sheet Janis Excel Discussion (Misc queries) 3 November 7th 07 03:21 AM
Find data from one sheet in another sheet [email protected] Excel Worksheet Functions 3 August 21st 06 07:08 PM
Find A Value In Sheet? BL69 Excel Discussion (Misc queries) 2 June 13th 05 06:06 PM
Find changes and add them to the new sheet sg[_4_] Excel Programming 0 October 27th 04 09:59 PM


All times are GMT +1. The time now is 03:04 PM.

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"