PC Review


Reply
Thread Tools Rate Thread

How to call out "other" open book

 
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      17th Jul 2007
Hi All.........
I have a little macro that works fine. However, I would like to change a
part of it that calls out the "other open workbook" to NOT be
hardcoded.......that is, to change the lines that read

Windows("ItemMaster.XLS").Activate
ActiveWindow.Close

to something that will do the same thing, but does not require the name
"ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
what name it might be.

Here's the whole macro for reference....

Sub ObtainNewData()
Dim s As String
s = Range("MainMenu!c17").Value
If Range("c17").Value <> "" Then
Workbooks.Open FileName:=s
Else
MsgBox s & " Not found"
End If
Sheets("sheet1").Select
Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")

Windows("ItemMaster.XLS").Activate
ActiveWindow.Close

Sheets("sheet1").Name = "ImportedData"
Sheets("MainMenu").Select
Range("e21").Select
End Sub

TIA
Vaya con Dios,
Chuck, CABGx3


 
Reply With Quote
 
 
 
 
Zone
Guest
Posts: n/a
 
      17th Jul 2007
Chuck, well, you could use something like
For k=1 to workbooks.count
if workbooks(k).name<>activeworkbook.name then
workbooks(k).activate
exit for
end if
Next k
But what if more than 2 workbooks are open? How will Excel know which
one you want? James

On Jul 17, 7:42?am, CLR <C...@discussions.microsoft.com> wrote:
> Hi All.........
> I have a little macro that works fine. However, I would like to change a
> part of it that calls out the "other open workbook" to NOT be
> hardcoded.......that is, to change the lines that read
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> to something that will do the same thing, but does not require the name
> "ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
> what name it might be.
>
> Here's the whole macro for reference....
>
> Sub ObtainNewData()
> Dim s As String
> s = Range("MainMenu!c17").Value
> If Range("c17").Value <> "" Then
> Workbooks.Open FileName:=s
> Else
> MsgBox s & " Not found"
> End If
> Sheets("sheet1").Select
> Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> Sheets("sheet1").Name = "ImportedData"
> Sheets("MainMenu").Select
> Range("e21").Select
> End Sub
>
> TIA
> Vaya con Dios,
> Chuck, CABGx3



 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      17th Jul 2007
Chuck,
You could use something like
For k=1 to workbooks.count
if workbooks(k).name<>activeworkbook.name then
workbooks(k).activate
exit for
end if
next k

But what if more than 2 workbooks are open? Then the "other" workbook
could be one of several. James

On Jul 17, 7:42?am, CLR <C...@discussions.microsoft.com> wrote:
> Hi All.........
> I have a little macro that works fine. However, I would like to change a
> part of it that calls out the "other open workbook" to NOT be
> hardcoded.......that is, to change the lines that read
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> to something that will do the same thing, but does not require the name
> "ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
> what name it might be.
>
> Here's the whole macro for reference....
>
> Sub ObtainNewData()
> Dim s As String
> s = Range("MainMenu!c17").Value
> If Range("c17").Value <> "" Then
> Workbooks.Open FileName:=s
> Else
> MsgBox s & " Not found"
> End If
> Sheets("sheet1").Select
> Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> Sheets("sheet1").Name = "ImportedData"
> Sheets("MainMenu").Select
> Range("e21").Select
> End Sub
>
> TIA
> Vaya con Dios,
> Chuck, CABGx3



 
Reply With Quote
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      17th Jul 2007
Cool.........that worked fine James, many thanks.
The opening and closing of additional workbooks is done in this instance
only under program control, so there will never be more than one "other" one
open at a time....but thanks for the concern....and thanks again for the help.

Vaya con Dios,
Chuck, CABGx3





"Zone" wrote:

> Chuck,
> You could use something like
> For k=1 to workbooks.count
> if workbooks(k).name<>activeworkbook.name then
> workbooks(k).activate
> exit for
> end if
> next k
>
> But what if more than 2 workbooks are open? Then the "other" workbook
> could be one of several. James
>
> On Jul 17, 7:42?am, CLR <C...@discussions.microsoft.com> wrote:
> > Hi All.........
> > I have a little macro that works fine. However, I would like to change a
> > part of it that calls out the "other open workbook" to NOT be
> > hardcoded.......that is, to change the lines that read
> >
> > Windows("ItemMaster.XLS").Activate
> > ActiveWindow.Close
> >
> > to something that will do the same thing, but does not require the name
> > "ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
> > what name it might be.
> >
> > Here's the whole macro for reference....
> >
> > Sub ObtainNewData()
> > Dim s As String
> > s = Range("MainMenu!c17").Value
> > If Range("c17").Value <> "" Then
> > Workbooks.Open FileName:=s
> > Else
> > MsgBox s & " Not found"
> > End If
> > Sheets("sheet1").Select
> > Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")
> >
> > Windows("ItemMaster.XLS").Activate
> > ActiveWindow.Close
> >
> > Sheets("sheet1").Name = "ImportedData"
> > Sheets("MainMenu").Select
> > Range("e21").Select
> > End Sub
> >
> > TIA
> > Vaya con Dios,
> > Chuck, CABGx3

>
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      17th Jul 2007
If only two visible windows (this will eliminate Personal.xls from the mix as
an example)

Sub BBB()
Dim WinDw As Window
For Each WinDw In Application.Windows
If WinDw.Visible = True And _
WinDw.Caption <> ThisWorkbook.Windows(1).Caption Then
WinDw.Activate
MsgBox WinDw.Caption
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"CLR" wrote:

> Hi All.........
> I have a little macro that works fine. However, I would like to change a
> part of it that calls out the "other open workbook" to NOT be
> hardcoded.......that is, to change the lines that read
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> to something that will do the same thing, but does not require the name
> "ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
> what name it might be.
>
> Here's the whole macro for reference....
>
> Sub ObtainNewData()
> Dim s As String
> s = Range("MainMenu!c17").Value
> If Range("c17").Value <> "" Then
> Workbooks.Open FileName:=s
> Else
> MsgBox s & " Not found"
> End If
> Sheets("sheet1").Select
> Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")
>
> Windows("ItemMaster.XLS").Activate
> ActiveWindow.Close
>
> Sheets("sheet1").Name = "ImportedData"
> Sheets("MainMenu").Select
> Range("e21").Select
> End Sub
>
> TIA
> Vaya con Dios,
> Chuck, CABGx3
>
>

 
Reply With Quote
 
=?Utf-8?B?Q0xS?=
Guest
Posts: n/a
 
      17th Jul 2007
Thanks Tom........didn't consider personal.xls. Although most of my users
don't have one, this will take care of the ones that do.........thanks again.

Vaya con Dios,
Chuck, CABGx3



"Tom Ogilvy" wrote:

> If only two visible windows (this will eliminate Personal.xls from the mix as
> an example)
>
> Sub BBB()
> Dim WinDw As Window
> For Each WinDw In Application.Windows
> If WinDw.Visible = True And _
> WinDw.Caption <> ThisWorkbook.Windows(1).Caption Then
> WinDw.Activate
> MsgBox WinDw.Caption
> End If
> Next
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "CLR" wrote:
>
> > Hi All.........
> > I have a little macro that works fine. However, I would like to change a
> > part of it that calls out the "other open workbook" to NOT be
> > hardcoded.......that is, to change the lines that read
> >
> > Windows("ItemMaster.XLS").Activate
> > ActiveWindow.Close
> >
> > to something that will do the same thing, but does not require the name
> > "ItemMaster.XLS" to be hard coded in, so that it will be selected no matter
> > what name it might be.
> >
> > Here's the whole macro for reference....
> >
> > Sub ObtainNewData()
> > Dim s As String
> > s = Range("MainMenu!c17").Value
> > If Range("c17").Value <> "" Then
> > Workbooks.Open FileName:=s
> > Else
> > MsgBox s & " Not found"
> > End If
> > Sheets("sheet1").Select
> > Sheets("sheet1").Copy After:=ThisWorkbook.Sheets("MainMenu")
> >
> > Windows("ItemMaster.XLS").Activate
> > ActiveWindow.Close
> >
> > Sheets("sheet1").Name = "ImportedData"
> > Sheets("MainMenu").Select
> > Range("e21").Select
> > End Sub
> >
> > TIA
> > Vaya con Dios,
> > Chuck, CABGx3
> >
> >

 
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
Outlook 2003 "phone call" label, add/open a box to enter Tel num =?Utf-8?B?R3JleWJsb2tl?= Microsoft Outlook Discussion 0 8th Aug 2006 01:26 PM
How Can I call A Macro From One "Work book" to Another "Work book"? zameer_india Microsoft Excel Discussion 1 4th Jul 2005 09:04 AM
How do I "hide" members of a "group" in my "outlook address book". =?Utf-8?B?ZGVlcHNlYTI5?= Microsoft Outlook Contacts 1 31st Jan 2005 12:40 AM
Outlook XP - viewing contacts when click on "To" or "cc" or "BCC:" - address book is emty be Microsoft Outlook Contacts 1 18th Jan 2004 10:12 AM
what is the difference between a ".wab", the "contacts" folder, and a "personal address book" albert Microsoft Outlook 2 11th Jan 2004 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 PM.