+ Reply to Thread
Results 1 to 17 of 17

Naming more than one active workbook

  1. #1
    Registered User
    Join Date
    06-01-2006
    Posts
    19

    Naming more than one active workbook

    I know how to name an active workbook with the following command:
    Set Form7 = ActiveWorkbook

    In this case I named the active workbook "Form7" which permits me to activate and interact with the workbook.

    Is it possible to name more than one active workbook (with different names) at the same time and be able to activate and interact with them? Apparently the way I use the command, the most recent workbook is the active workbook and previous active workbooks that were given names are no longer valid.

  2. #2
    Ardus Petus
    Guest

    Re: Naming more than one active workbook

    set Form1=WorkBooks("Something.xls")

    HTH
    --
    AP

    "grantj" <[email protected]> a écrit dans
    le message de news: [email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  3. #3
    Registered User
    Join Date
    06-01-2006
    Posts
    19

    Re: Naming more than one active workbook

    Will this command work even if I don't know the name of the active workbook (something.xls)? The user will have the ability to rename the workbook prior to using the macro.

  4. #4
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    That's not the case though. Once you have set an object variable it works
    until that object no longer exists. It doens't even have to be the active
    workbook - as long as it is a reference to a workbook. Making another
    workbook active should not stop the variable from referring to the original
    workbook unless you reset it to the new one.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  5. #5
    Ardus Petus
    Guest

    Re: Naming more than one active workbook

    The Workbooks collection represents the whole of currently opened worbooks.

    If you want to reference the 1st opened workbook, you may write:
    set wb1 = Workbooks(1)

    That does not make much sense to me

    HTH
    --
    AP

    "grantj" <[email protected]> a écrit dans
    le message de news: [email protected]...
    >
    > Will this command work even if I don't know the name of the active
    > workbook (something.xls)? The user will have the ability to rename
    > the workbook prior to using the macro.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  6. #6
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    That's not the case though. Once you have set an object variable it works
    until that object no longer exists. It doens't even have to be the active
    workbook - as long as it is a reference to a workbook. Making another
    workbook active should not stop the variable from referring to the original
    workbook unless you reset it to the new one.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  7. #7
    Ardus Petus
    Guest

    Re: Naming more than one active workbook

    The Workbooks collection represents the whole of currently opened worbooks.

    If you want to reference the 1st opened workbook, you may write:
    set wb1 = Workbooks(1)

    That does not make much sense to me

    HTH
    --
    AP

    "grantj" <[email protected]> a écrit dans
    le message de news: [email protected]...
    >
    > Will this command work even if I don't know the name of the active
    > workbook (something.xls)? The user will have the ability to rename
    > the workbook prior to using the macro.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  8. #8
    Ardus Petus
    Guest

    Re: Naming more than one active workbook

    The Workbooks collection represents the whole of currently opened worbooks.

    If you want to reference the 1st opened workbook, you may write:
    set wb1 = Workbooks(1)

    That does not make much sense to me

    HTH
    --
    AP

    "grantj" <[email protected]> a écrit dans
    le message de news: [email protected]...
    >
    > Will this command work even if I don't know the name of the active
    > workbook (something.xls)? The user will have the ability to rename
    > the workbook prior to using the macro.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  9. #9
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    That's not the case though. Once you have set an object variable it works
    until that object no longer exists. It doens't even have to be the active
    workbook - as long as it is a reference to a workbook. Making another
    workbook active should not stop the variable from referring to the original
    workbook unless you reset it to the new one.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  10. #10
    Registered User
    Join Date
    06-01-2006
    Posts
    19

    Re: Naming more than one active workbook

    This is how I have it set-up (and doesn't work):

    (The user begins in a workbook which is named something by the user. I do not know the name. I want to name it "Compass3")
    Set Compass3 = ActiveWorkbook

    (next the user willl open a new file of which I name it "Form7". This works fine)
    Application.FindFile
    Set Form7 = ActiveWorkbook

    (After performing some operations, the "Form7" workbook is closed. This works fine)
    Form7.Activate
    Application.CutCopyMode = False
    Form7.Close True

    (now when I activate "Compass3". I get an error: Object Required)
    Compass3.Activate

    Any suggestions??

    Quote Originally Posted by Jeff Standen
    That's not the case though. Once you have set an object variable it works
    until that object no longer exists. It doens't even have to be the active
    workbook - as long as it is a reference to a workbook. Making another
    workbook active should not stop the variable from referring to the original
    workbook unless you reset it to the new one.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >

  11. #11
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    Is this all within the same procedure? If the first one is set then the code
    stops, it will lose the reference as it isn't running anymore. Can you post
    the relevant code as this should most definitely work. Try this to
    demonstrate:

    Sub test()
    Dim a As Workbook
    Dim b As Workbook

    Set a = Workbooks.Add
    Set b = Workbooks.Add
    a.Activate
    Call MsgBox("First one")
    b.Activate
    Call MsgBox("Second one")
    a.Activate
    Call MsgBox("First one again")
    b.Activate
    Call MsgBox("And so on")
    a.close false
    b.close false
    End Sub

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > This is how I have it set-up (and doesn't work):
    >
    > (The user begins in a workbook which is named something by the user. I
    > do not know the name. I want to name it "Compass3")
    > Set Compass3 = ActiveWorkbook
    >
    > (next the user willl open a new file of which I name it "Form7". This
    > works fine)
    > Application.FindFile
    > Set Form7 = ActiveWorkbook
    >
    > (After performing some operations, the "Form7" workbook is closed.
    > This works fine)
    > Form7.Activate
    > Application.CutCopyMode = False
    > Form7.Close True
    >
    > (now when I activate "Compass3". I get an error: Object Required)
    > Compass3.Activate
    >
    > Any suggestions??
    >
    > Jeff Standen Wrote:
    >> That's not the case though. Once you have set an object variable it
    >> works
    >> until that object no longer exists. It doens't even have to be the
    >> active
    >> workbook - as long as it is a reference to a workbook. Making another
    >> workbook active should not stop the variable from referring to the
    >> original
    >> workbook unless you reset it to the new one.
    >>
    >> Jeff
    >>
    >> "grantj" <[email protected]> wrote
    >> in
    >> message news:[email protected]...
    >> >
    >> > I know how to name an active workbook with the following command:
    >> > Set Form7 = ActiveWorkbook
    >> >
    >> > In this case I named the active workbook "Form7" which permits me to
    >> > activate and interact with the workbook.
    >> >
    >> > Is it possible to name more than one active workbook (with different
    >> > names) at the same time and be able to activate and interact with

    >> them?
    >> > Apparently the way I use the command, the most recent workbook is

    >> the
    >> > active workbook and previous active workbooks that were given names

    >> are
    >> > no longer valid.
    >> >
    >> >
    >> > --
    >> > grantj
    >> >

    >> ------------------------------------------------------------------------
    >> > grantj's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=35021
    >> > View this thread:

    >> http://www.excelforum.com/showthread...hreadid=548972
    >> >

    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  12. #12
    Registered User
    Join Date
    06-01-2006
    Posts
    19

    Re: Naming more than one active workbook

    Almost but not quite. The user begins by running a macro in an existing workbook. I do not know the name of this workbook, but I want to assign a name "Compass3" and activate this workbook after the macro opens another workbook, assigns a name of "Form7" and then closes "Form7".

    Quote Originally Posted by Jeff Standen
    Is this all within the same procedure? If the first one is set then the code
    stops, it will lose the reference as it isn't running anymore. Can you post
    the relevant code as this should most definitely work. Try this to
    demonstrate:

    Sub test()
    Dim a As Workbook
    Dim b As Workbook

    Set a = Workbooks.Add
    Set b = Workbooks.Add
    a.Activate
    Call MsgBox("First one")
    b.Activate
    Call MsgBox("Second one")
    a.Activate
    Call MsgBox("First one again")
    b.Activate
    Call MsgBox("And so on")
    a.close false
    b.close false
    End Sub

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > This is how I have it set-up (and doesn't work):
    >
    > (The user begins in a workbook which is named something by the user. I
    > do not know the name. I want to name it "Compass3")
    > Set Compass3 = ActiveWorkbook
    >
    > (next the user willl open a new file of which I name it "Form7". This
    > works fine)
    > Application.FindFile
    > Set Form7 = ActiveWorkbook
    >
    > (After performing some operations, the "Form7" workbook is closed.
    > This works fine)
    > Form7.Activate
    > Application.CutCopyMode = False
    > Form7.Close True
    >
    > (now when I activate "Compass3". I get an error: Object Required)
    > Compass3.Activate
    >
    > Any suggestions??
    >
    > Jeff Standen Wrote:
    >> That's not the case though. Once you have set an object variable it
    >> works
    >> until that object no longer exists. It doens't even have to be the
    >> active
    >> workbook - as long as it is a reference to a workbook. Making another
    >> workbook active should not stop the variable from referring to the
    >> original
    >> workbook unless you reset it to the new one.
    >>
    >> Jeff
    >>
    >> "grantj" <[email protected]> wrote
    >> in
    >> message news:[email protected]...
    >> >
    >> > I know how to name an active workbook with the following command:
    >> > Set Form7 = ActiveWorkbook
    >> >
    >> > In this case I named the active workbook "Form7" which permits me to
    >> > activate and interact with the workbook.
    >> >
    >> > Is it possible to name more than one active workbook (with different
    >> > names) at the same time and be able to activate and interact with

    >> them?
    >> > Apparently the way I use the command, the most recent workbook is

    >> the
    >> > active workbook and previous active workbooks that were given names

    >> are
    >> > no longer valid.
    >> >
    >> >
    >> > --
    >> > grantj
    >> >

    >> ------------------------------------------------------------------------
    >> > grantj's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=35021
    >> > View this thread:

    >> http://www.excelforum.com/showthread...hreadid=548972
    >> >

    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >

  13. #13
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    My code refers to 2 workbooks at the same time so it is possible - can you
    post your code?

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Almost but not quite. The user begins by running a macro in an existing
    > workbook. I do not know the name of this workbook, but I want to assign
    > a name "Compass3" and activate this workbook after the macro opens
    > another workbook, assigns a name of "Form7" and then closes "Form7".
    >
    > Jeff Standen Wrote:
    >> Is this all within the same procedure? If the first one is set then the
    >> code
    >> stops, it will lose the reference as it isn't running anymore. Can you
    >> post
    >> the relevant code as this should most definitely work. Try this to
    >> demonstrate:
    >>
    >> Sub test()
    >> Dim a As Workbook
    >> Dim b As Workbook
    >>
    >> Set a = Workbooks.Add
    >> Set b = Workbooks.Add
    >> a.Activate
    >> Call MsgBox("First one")
    >> b.Activate
    >> Call MsgBox("Second one")
    >> a.Activate
    >> Call MsgBox("First one again")
    >> b.Activate
    >> Call MsgBox("And so on")
    >> a.close false
    >> b.close false
    >> End Sub
    >>
    >> "grantj" <[email protected]> wrote
    >> in
    >> message news:[email protected]...
    >> >
    >> > This is how I have it set-up (and doesn't work):
    >> >
    >> > (The user begins in a workbook which is named something by the user.

    >> I
    >> > do not know the name. I want to name it "Compass3")
    >> > Set Compass3 = ActiveWorkbook
    >> >
    >> > (next the user willl open a new file of which I name it "Form7".

    >> This
    >> > works fine)
    >> > Application.FindFile
    >> > Set Form7 = ActiveWorkbook
    >> >
    >> > (After performing some operations, the "Form7" workbook is closed.
    >> > This works fine)
    >> > Form7.Activate
    >> > Application.CutCopyMode = False
    >> > Form7.Close True
    >> >
    >> > (now when I activate "Compass3". I get an error: Object Required)
    >> > Compass3.Activate
    >> >
    >> > Any suggestions??
    >> >
    >> > Jeff Standen Wrote:
    >> >> That's not the case though. Once you have set an object variable it
    >> >> works
    >> >> until that object no longer exists. It doens't even have to be the
    >> >> active
    >> >> workbook - as long as it is a reference to a workbook. Making

    >> another
    >> >> workbook active should not stop the variable from referring to the
    >> >> original
    >> >> workbook unless you reset it to the new one.
    >> >>
    >> >> Jeff
    >> >>
    >> >> "grantj" <[email protected]>

    >> wrote
    >> >> in
    >> >> message news:[email protected]...
    >> >> >
    >> >> > I know how to name an active workbook with the following command:
    >> >> > Set Form7 = ActiveWorkbook
    >> >> >
    >> >> > In this case I named the active workbook "Form7" which permits me

    >> to
    >> >> > activate and interact with the workbook.
    >> >> >
    >> >> > Is it possible to name more than one active workbook (with

    >> different
    >> >> > names) at the same time and be able to activate and interact with
    >> >> them?
    >> >> > Apparently the way I use the command, the most recent workbook is
    >> >> the
    >> >> > active workbook and previous active workbooks that were given

    >> names
    >> >> are
    >> >> > no longer valid.
    >> >> >
    >> >> >
    >> >> > --
    >> >> > grantj
    >> >> >
    >> >>

    >> ------------------------------------------------------------------------
    >> >> > grantj's Profile:
    >> >> > http://www.excelforum.com/member.php...o&userid=35021
    >> >> > View this thread:
    >> >> http://www.excelforum.com/showthread...hreadid=548972
    >> >> >
    >> >
    >> >
    >> > --
    >> > grantj
    >> >

    >> ------------------------------------------------------------------------
    >> > grantj's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=35021
    >> > View this thread:

    >> http://www.excelforum.com/showthread...hreadid=548972
    >> >

    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  14. #14
    Registered User
    Join Date
    06-01-2006
    Posts
    19

    Re: Naming more than one active workbook

    Here is the code. Is there a way to attach the Excel workbooks being referenced?

    Sub Copy_Form_7()

    Set Compass3 = ActiveWorkbook

    If MsgBox("This Macro will copy CFC Form 7 data into the COMPASS3 program. Do you want to continue?", vbYesNo) = vbYes Then
    Workbooks.Open Filename:="C:\Compass3\Compass Form7.xls", UpdateLinks:=3
    Application.Run "'Compass Form7.xls'!OpenFormSevenFile"
    End If

    End Sub

    Sub OpenFormSevenFile()

    MsgBox ("Select and open a CFC Form 7 file (short or long form).")
    Application.FindFile
    Set Form7 = ActiveWorkbook

    ' Copy Statement of Operations
    Sheets("Page 1").Select
    Range("A:G").Select
    Selection.Copy
    Windows("Compass Form7.xls").Activate
    Sheets("Page 1").Visible = True
    Sheets("Page 1").Select
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("Page 1").Visible = False

    ' Copy Balance Sheet
    Form7.Activate
    Sheets("Page 2").Select
    Cells.Select
    Selection.Copy
    Windows("Compass Form7.xls").Activate
    Sheets("Page 2").Visible = True
    Sheets("Page 2").Select
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("Page 2").Visible = False

    ' Close Form 7 workbook
    Form7.Activate
    Application.CutCopyMode = False
    Sheets("Page 1").Activate
    Range("A1").Select
    Form7.Close False

    copy_Years

    End Sub




    Sub copy_Years()

    ' Copy the first future year into "Compass Form 7" spreadsheet
    ' to determine where to paste the Form 7 data
    Compass3.Activate
    Sheets("Balance Sheet Information").Select
    Range("AE5").Select
    Selection.Copy
    Windows("Compass Form7.xls").Activate
    Sheets("Sheet1").Select
    Range("E4").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    If Range("Year") = 1 Then
    Copy_Year_1
    Else
    If Range("Year") = 2 Then
    Copy_Year_2
    Else
    If Range("Year") = 3 Then
    Copy_Year_3
    Else
    End If
    End If
    End If

    End Sub




    Sub Copy_Year_1()

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = True
    Sheets("Workhorse").Select
    Range("C9:C17").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AE25").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Select
    Range("C19:C25").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AE35").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("AE25").Select

    Compass3.Activate
    Application.CutCopyMode = False
    Sheets("General Information").Select
    Range("K9").Select

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = False
    Windows("Compass Form7.xls").Close True

    End Sub




    Sub Copy_Year_2()

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = True
    Sheets("Workhorse").Select
    Range("C9:C17").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AF25").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Select
    Range("C19:C25").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AF35").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("AF25").Select

    Compass3.Activate
    Application.CutCopyMode = False
    Sheets("General Information").Select

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = False
    Windows("Compass Form7.xls").Close True
    Range("K9").Select
    End Sub




    Sub Copy_Year_3()

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = True
    Sheets("Workhorse").Select
    Range("C9:C17").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AG25").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Select
    Range("C19:C25").Select
    Selection.Copy
    Compass3.Activate
    Sheets("Expense Information").Select
    Range("AG35").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("AE25").Select

    Compass3.Activate
    Application.CutCopyMode = False
    Sheets("General Information").Select

    Windows("Compass Form7.xls").Activate
    Sheets("Workhorse").Visible = False
    Windows("Compass Form7.xls").Close True
    Range("K9").Select
    End Sub



    Quote Originally Posted by Jeff Standen
    That's not the case though. Once you have set an object variable it works
    until that object no longer exists. It doens't even have to be the active
    workbook - as long as it is a reference to a workbook. Making another
    workbook active should not stop the variable from referring to the original
    workbook unless you reset it to the new one.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I know how to name an active workbook with the following command:
    > Set Form7 = ActiveWorkbook
    >
    > In this case I named the active workbook "Form7" which permits me to
    > activate and interact with the workbook.
    >
    > Is it possible to name more than one active workbook (with different
    > names) at the same time and be able to activate and interact with them?
    > Apparently the way I use the command, the most recent workbook is the
    > active workbook and previous active workbooks that were given names are
    > no longer valid.
    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >

  15. #15
    Tim Williams
    Guest

    Re: Naming more than one active workbook

    "grantj" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Almost but not quite. The user begins by running a macro in an existing
    > workbook. I do not know the name of this workbook, but I want to assign
    > a name "Compass3" and activate this workbook after the macro opens
    > another workbook, assigns a name of "Form7" and then closes "Form7".



    ThisWorkbook.Activate

    ThisWorkbook always refers to the workbook containing the running code.

    --
    Tim Williams
    Palo Alto, CA


    >




  16. #16
    Jeff Standen
    Guest

    Re: Naming more than one active workbook

    If I'm reading this right, the code appears to be in two seperate workbooks.
    As I understand it, after this line:

    Application.Run "'Compass Form7.xls'!OpenFormSevenFile"

    runs, the procedure stops, so the variables are lost - they aren't carried
    over from one procedure to the other as their scope is only within the
    workbook (or procedure, or module) that they are defined in. I think if you
    define your object variable as Global (instead of public or whatever) it may
    carry over, otherwise store the module path somewhere on one of the
    workbooks (eg in a Name) and pick it up again in the second workbook. Or,
    more simply, put all the code in one workbook - it's far tidier that way.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Here is the code. Is there a way to attach the Excel workbooks being
    > referenced?
    >
    > Sub Copy_Form_7()
    >
    > Set Compass3 = ActiveWorkbook
    >
    > If MsgBox("This Macro will copy CFC Form 7 data into the COMPASS3
    > program. Do you want to continue?", vbYesNo) = vbYes Then
    > Workbooks.Open Filename:="C:\Compass3\Compass Form7.xls",
    > UpdateLinks:=3
    > Application.Run "'Compass Form7.xls'!OpenFormSevenFile"
    > End If
    >
    > End Sub
    >
    > Sub OpenFormSevenFile()
    >
    > MsgBox ("Select and open a CFC Form 7 file (short or long form).")
    > Application.FindFile
    > Set Form7 = ActiveWorkbook
    >
    > ' Copy Statement of Operations
    > Sheets("Page 1").Select
    > Range("A:G").Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Page 1").Visible = True
    > Sheets("Page 1").Select
    > Range("A1").Select
    > ActiveSheet.Paste
    > Sheets("Page 1").Visible = False
    >
    > ' Copy Balance Sheet
    > Form7.Activate
    > Sheets("Page 2").Select
    > Cells.Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Page 2").Visible = True
    > Sheets("Page 2").Select
    > Range("A1").Select
    > ActiveSheet.Paste
    > Sheets("Page 2").Visible = False
    >
    > ' Close Form 7 workbook
    > Form7.Activate
    > Application.CutCopyMode = False
    > Sheets("Page 1").Activate
    > Range("A1").Select
    > Form7.Close False
    >
    > copy_Years
    >
    > End Sub
    >
    >
    >
    >
    > Sub copy_Years()
    >
    > ' Copy the first future year into "Compass Form 7" spreadsheet
    > ' to determine where to paste the Form 7 data
    > Compass3.Activate
    > Sheets("Balance Sheet Information").Select
    > Range("AE5").Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Sheet1").Select
    > Range("E4").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > If Range("Year") = 1 Then
    > Copy_Year_1
    > Else
    > If Range("Year") = 2 Then
    > Copy_Year_2
    > Else
    > If Range("Year") = 3 Then
    > Copy_Year_3
    > Else
    > End If
    > End If
    > End If
    >
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_1()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AE25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AE35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AE25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    > Range("K9").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    >
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_2()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AF25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AF35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AF25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    > Range("K9").Select
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_3()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AG25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AG35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AE25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    > Range("K9").Select
    > End Sub
    >
    >
    >
    > Jeff Standen Wrote:
    >> That's not the case though. Once you have set an object variable it
    >> works
    >> until that object no longer exists. It doens't even have to be the
    >> active
    >> workbook - as long as it is a reference to a workbook. Making another
    >> workbook active should not stop the variable from referring to the
    >> original
    >> workbook unless you reset it to the new one.
    >>
    >> Jeff
    >>
    >> "grantj" <[email protected]> wrote
    >> in
    >> message news:[email protected]...
    >> >
    >> > I know how to name an active workbook with the following command:
    >> > Set Form7 = ActiveWorkbook
    >> >
    >> > In this case I named the active workbook "Form7" which permits me to
    >> > activate and interact with the workbook.
    >> >
    >> > Is it possible to name more than one active workbook (with different
    >> > names) at the same time and be able to activate and interact with

    >> them?
    >> > Apparently the way I use the command, the most recent workbook is

    >> the
    >> > active workbook and previous active workbooks that were given names

    >> are
    >> > no longer valid.
    >> >
    >> >
    >> > --
    >> > grantj
    >> >

    >> ------------------------------------------------------------------------
    >> > grantj's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=35021
    >> > View this thread:

    >> http://www.excelforum.com/showthread...hreadid=548972
    >> >

    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >




  17. #17
    Registered User
    Join Date
    06-01-2006
    Posts
    19
    Thanks Jeff

    Quote Originally Posted by Jeff Standen
    If I'm reading this right, the code appears to be in two seperate workbooks.
    As I understand it, after this line:

    Application.Run "'Compass Form7.xls'!OpenFormSevenFile"

    runs, the procedure stops, so the variables are lost - they aren't carried
    over from one procedure to the other as their scope is only within the
    workbook (or procedure, or module) that they are defined in. I think if you
    define your object variable as Global (instead of public or whatever) it may
    carry over, otherwise store the module path somewhere on one of the
    workbooks (eg in a Name) and pick it up again in the second workbook. Or,
    more simply, put all the code in one workbook - it's far tidier that way.

    Jeff

    "grantj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Here is the code. Is there a way to attach the Excel workbooks being
    > referenced?
    >
    > Sub Copy_Form_7()
    >
    > Set Compass3 = ActiveWorkbook
    >
    > If MsgBox("This Macro will copy CFC Form 7 data into the COMPASS3
    > program. Do you want to continue?", vbYesNo) = vbYes Then
    > Workbooks.Open Filename:="C:\Compass3\Compass Form7.xls",
    > UpdateLinks:=3
    > Application.Run "'Compass Form7.xls'!OpenFormSevenFile"
    > End If
    >
    > End Sub
    >
    > Sub OpenFormSevenFile()
    >
    > MsgBox ("Select and open a CFC Form 7 file (short or long form).")
    > Application.FindFile
    > Set Form7 = ActiveWorkbook
    >
    > ' Copy Statement of Operations
    > Sheets("Page 1").Select
    > Range("A:G").Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Page 1").Visible = True
    > Sheets("Page 1").Select
    > Range("A1").Select
    > ActiveSheet.Paste
    > Sheets("Page 1").Visible = False
    >
    > ' Copy Balance Sheet
    > Form7.Activate
    > Sheets("Page 2").Select
    > Cells.Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Page 2").Visible = True
    > Sheets("Page 2").Select
    > Range("A1").Select
    > ActiveSheet.Paste
    > Sheets("Page 2").Visible = False
    >
    > ' Close Form 7 workbook
    > Form7.Activate
    > Application.CutCopyMode = False
    > Sheets("Page 1").Activate
    > Range("A1").Select
    > Form7.Close False
    >
    > copy_Years
    >
    > End Sub
    >
    >
    >
    >
    > Sub copy_Years()
    >
    > ' Copy the first future year into "Compass Form 7" spreadsheet
    > ' to determine where to paste the Form 7 data
    > Compass3.Activate
    > Sheets("Balance Sheet Information").Select
    > Range("AE5").Select
    > Selection.Copy
    > Windows("Compass Form7.xls").Activate
    > Sheets("Sheet1").Select
    > Range("E4").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > If Range("Year") = 1 Then
    > Copy_Year_1
    > Else
    > If Range("Year") = 2 Then
    > Copy_Year_2
    > Else
    > If Range("Year") = 3 Then
    > Copy_Year_3
    > Else
    > End If
    > End If
    > End If
    >
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_1()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AE25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AE35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AE25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    > Range("K9").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    >
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_2()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AF25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AF35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AF25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    > Range("K9").Select
    > End Sub
    >
    >
    >
    >
    > Sub Copy_Year_3()
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = True
    > Sheets("Workhorse").Select
    > Range("C9:C17").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AG25").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Select
    > Range("C19:C25").Select
    > Selection.Copy
    > Compass3.Activate
    > Sheets("Expense Information").Select
    > Range("AG35").Select
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
    > SkipBlanks:= _
    > False, Transpose:=False
    > Range("AE25").Select
    >
    > Compass3.Activate
    > Application.CutCopyMode = False
    > Sheets("General Information").Select
    >
    > Windows("Compass Form7.xls").Activate
    > Sheets("Workhorse").Visible = False
    > Windows("Compass Form7.xls").Close True
    > Range("K9").Select
    > End Sub
    >
    >
    >
    > Jeff Standen Wrote:
    >> That's not the case though. Once you have set an object variable it
    >> works
    >> until that object no longer exists. It doens't even have to be the
    >> active
    >> workbook - as long as it is a reference to a workbook. Making another
    >> workbook active should not stop the variable from referring to the
    >> original
    >> workbook unless you reset it to the new one.
    >>
    >> Jeff
    >>
    >> "grantj" <[email protected]> wrote
    >> in
    >> message news:[email protected]...
    >> >
    >> > I know how to name an active workbook with the following command:
    >> > Set Form7 = ActiveWorkbook
    >> >
    >> > In this case I named the active workbook "Form7" which permits me to
    >> > activate and interact with the workbook.
    >> >
    >> > Is it possible to name more than one active workbook (with different
    >> > names) at the same time and be able to activate and interact with

    >> them?
    >> > Apparently the way I use the command, the most recent workbook is

    >> the
    >> > active workbook and previous active workbooks that were given names

    >> are
    >> > no longer valid.
    >> >
    >> >
    >> > --
    >> > grantj
    >> >

    >> ------------------------------------------------------------------------
    >> > grantj's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=35021
    >> > View this thread:

    >> http://www.excelforum.com/showthread...hreadid=548972
    >> >

    >
    >
    > --
    > grantj
    > ------------------------------------------------------------------------
    > grantj's Profile:
    > http://www.excelforum.com/member.php...o&userid=35021
    > View this thread: http://www.excelforum.com/showthread...hreadid=548972
    >

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1