Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default How to call out "other" open book

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default How to call out "other" open book

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 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default How to call out "other" open book

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 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default How to call out "other" open book

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 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to call out "other" open book

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




  #6   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default How to call out "other" open book

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
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
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
conditional formula to show "open" or "closed" SBS Excel Worksheet Functions 6 January 28th 06 01:48 AM
Call a sub statement in "Personal Macro Workbook" from "ThisWorkbo QC Coug Excel Programming 1 August 26th 05 07:09 PM


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

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"