Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default import sheets of name selected


import sheets


i need to import sheets of following names from "MYProject.xls" in m
new workbook.

RULES, CONDITIONS, ROUTING, ZONES.


Only check above sheet names in MyProject.xls and import in new wrkbk
If not found any then display its name in msgbox

--
ilyaskaz
-----------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...fo&userid=2396
View this thread: http://www.excelforum.com/showthread.php?threadid=37667

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default import sheets of name selected


Is my question is cleared?

--
ilyaskaz
-----------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...fo&userid=2396
View this thread: http://www.excelforum.com/showthread.php?threadid=37667

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default import sheets of name selected

Assume MyProject.xls is open

Dim v as Variant
Dim s as String
Dim s1 as String
Dim iloc as Long
s = "#RULES#CONDITIONS#ROUTING#ZONES#"
s1 = s
Redim v(0 to 0)
for each sh in Workbooks("Myproject.xls").Worksheets
iloc = instr(1,"#" & sh.Name & "#",s,vbTextCompare)
if iloc < 0 then
v(ubound(v)) = sh.Name
s = Replace(s,sh.Name & "#","")
redim Preserve v(0 to ubound(v) + 1)
end if
Next
if len(s) < s1 then
Redim preserve v(0 to ubound(v)-1)
workbooks("Myproject.xls").Worksheets(v).copy
End if
if len(s) 1 then
s = Right(s,len(s)-1)
s = Replace(s,"#",vbCr)
msgbox "Sheets not found: " & vbCr & s
End If

--
Regards,
Tom Ogilvy

"ilyaskazi" wrote
in message ...

import sheets


i need to import sheets of following names from "MYProject.xls" in my
new workbook.

RULES, CONDITIONS, ROUTING, ZONES.


Only check above sheet names in MyProject.xls and import in new wrkbk.
If not found any then display its name in msgbox.


--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile:

http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=376676



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default import sheets of name selected

Option Explicit

Public Sub GetSheets()

Dim wbP As Workbook
Dim ws As Worksheet
Dim MySheets() As Variant
Dim index As Long
MySheets = Array("RULES", "CONDITIONS", "ROUTING", "ZONES")
Set wbP = Workbooks.Open("C:\MyProject.xls")

For index = LBound(MySheets, 1) To UBound(MySheets, 1)

Set ws = wbP.Worksheets(MySheets(index))

ws.Copy ThisWorkbook.Sheets(1)


Next


wbP.Close False



"ilyaskazi" wrote:


import sheets


i need to import sheets of following names from "MYProject.xls" in my
new workbook.

RULES, CONDITIONS, ROUTING, ZONES.


Only check above sheet names in MyProject.xls and import in new wrkbk.
If not found any then display its name in msgbox.


--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=376676


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default import sheets of name selected


Tom,

I was not able to get any output from your code, bcoz it gives me debu
messages. Whereas..


Patrick,
Your code was successful to import sheets only if array containin
names matches with workbook sheet names.

But what about if array containing names does not found any i
workbook???
Suppose workbook does not contain sheets which are required to import
then display msgbox with its sheet-name not found.

Plz check the same and let me know

--
ilyaskaz
-----------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...fo&userid=2396
View this thread: http://www.excelforum.com/showthread.php?threadid=37667



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default import sheets of name selected

Here is a slight revision that worked perfectly for me, but if you want to
wait for Patrick, knock yourself out.

Sub abc()
Dim v As Variant
Dim s As String
Dim s1 As String
Dim iloc As Long
s = "#RULES#CONDITIONS#ROUTING#ZONES#"
s1 = s
ReDim v(0 To 0)
For Each sh In Workbooks("Myproject.xls").Worksheets
iloc = InStr(1, s, "#" & sh.Name & "#", vbTextCompare)
If iloc < 0 Then
v(UBound(v)) = sh.Name
s = Replace(s, UCase(sh.Name) & "#", "")
ReDim Preserve v(0 To UBound(v) + 1)
End If
Next
If Len(s) < Len(s1) Then
ReDim Preserve v(0 To UBound(v) - 1)
Workbooks("Myproject.xls").Worksheets(v).Copy
End If
If Len(s) 1 Then
s = Right(s, Len(s) - 1)
s = Replace(s, "#", vbCr)
MsgBox "Sheets not found: " & vbCr & s
End If

End Sub

--
Regards,
Tom Ogilvy

"ilyaskazi" wrote
in message ...

Tom,

I was not able to get any output from your code, bcoz it gives me debug
messages. Whereas..


Patrick,
Your code was successful to import sheets only if array containing
names matches with workbook sheet names.

But what about if array containing names does not found any in
workbook???
Suppose workbook does not contain sheets which are required to import,
then display msgbox with its sheet-name not found.

Plz check the same and let me know.


--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile:

http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=376676



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 to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
Excel should be able to import selected data from MS Word family1935 Excel Discussion (Misc queries) 0 February 13th 06 08:36 PM
Can you save options selected in Text Import Wizard? Gary Brown[_5_] Excel Programming 2 April 19th 05 02:09 PM
Import selected data J Excel Programming 1 February 14th 05 05:53 PM
Import selected lines from an Ascii file drbobsled Excel Programming 1 June 23rd 04 12:19 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"