PC Review


Reply
Thread Tools Rate Thread

bring focus to workbook with variable name

 
 
Jacob
Guest
Posts: n/a
 
      9th Nov 2006
my program runs from a userform and uses one workbook. there is a link
on the userform, however, that can open another workbook. if this
other workbook is opened, the userform will interact with that workbook
since it is the active one. I need the original workbook to be
activated before manipulating the form again. I was able to solve this
using the following code in every section that referred to the original
workbook:

Dim WB1 As Workbook
Set WB1 = Workbooks("<filename>.xls")
WB1.Activate

I then realized that I have a save as button on the userform and the
workbook will often be saved with a different name rendering the above
code useless, or worse. is there a way around this? thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      9th Nov 2006
The problem may be that you are using a constant for the filename. Once the
file has been save with a new name then:

Dim s As String
s = Selection.Worksheet.Parent.Name

should represent the latest filename. Then:

Set WB1 = Workbooks(s)
--
Gary's Student


"Jacob" wrote:

> my program runs from a userform and uses one workbook. there is a link
> on the userform, however, that can open another workbook. if this
> other workbook is opened, the userform will interact with that workbook
> since it is the active one. I need the original workbook to be
> activated before manipulating the form again. I was able to solve this
> using the following code in every section that referred to the original
> workbook:
>
> Dim WB1 As Workbook
> Set WB1 = Workbooks("<filename>.xls")
> WB1.Activate
>
> I then realized that I have a save as button on the userform and the
> workbook will often be saved with a different name rendering the above
> code useless, or worse. is there a way around this? thanks.
>
>

 
Reply With Quote
 
Jacob
Guest
Posts: n/a
 
      9th Nov 2006
thanks for your help. that should work, but now i am realizing that
there are a lot of other actions that need the original workbook to be
active. it seems silly to place this everywhere where there is
interaction. It seems that it would be best to some how activate the
workbook whenever that particular userform is being used. is there a
way to do this?



On Nov 9, 12:25 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> The problem may be that you are using a constant for the filename. Once the
> file has been save with a new name then:
>
> Dim s As String
> s = Selection.Worksheet.Parent.Name
>
> should represent the latest filename. Then:
>
> Set WB1 = Workbooks(s)
> --
> Gary's Student
>
> "Jacob" wrote:
> > my program runs from a userform and uses one workbook. there is a link
> > on the userform, however, that can open another workbook. if this
> > other workbook is opened, the userform will interact with that workbook
> > since it is the active one. I need the original workbook to be
> > activated before manipulating the form again. I was able to solve this
> > using the following code in every section that referred to the original
> > workbook:

>
> > Dim WB1 As Workbook
> > Set WB1 = Workbooks("<filename>.xls")
> > WB1.Activate

>
> > I then realized that I have a save as button on the userform and the
> > workbook will often be saved with a different name rendering the above
> > code useless, or worse. is there a way around this? thanks.


 
Reply With Quote
 
Jacob
Guest
Posts: n/a
 
      9th Nov 2006
I suppose a better question would be: is there a way to associate the
workbook with the userform and all its contents and actions regardless
of the file name?


On Nov 9, 1:57 pm, "Jacob" <jlong...@gmail.com> wrote:
> thanks for your help. that should work, but now i am realizing that
> there are a lot of other actions that need the original workbook to be
> active. it seems silly to place this everywhere where there is
> interaction. It seems that it would be best to some how activate the
> workbook whenever that particular userform is being used. is there a
> way to do this?
>
> On Nov 9, 12:25 pm, Gary''s Student
>
> <GarysStud...@discussions.microsoft.com> wrote:
> > The problem may be that you are using a constant for the filename. Once the
> > file has been save with a new name then:

>
> > Dim s As String
> > s = Selection.Worksheet.Parent.Name

>
> > should represent the latest filename. Then:

>
> > Set WB1 = Workbooks(s)
> > --
> > Gary's Student

>
> > "Jacob" wrote:
> > > my program runs from a userform and uses one workbook. there is a link
> > > on the userform, however, that can open another workbook. if this
> > > other workbook is opened, the userform will interact with that workbook
> > > since it is the active one. I need the original workbook to be
> > > activated before manipulating the form again. I was able to solve this
> > > using the following code in every section that referred to the original
> > > workbook:

>
> > > Dim WB1 As Workbook
> > > Set WB1 = Workbooks("<filename>.xls")
> > > WB1.Activate

>
> > > I then realized that I have a save as button on the userform and the
> > > workbook will often be saved with a different name rendering the above
> > > code useless, or worse. is there a way around this? thanks.


 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      9th Nov 2006
I don't know.

If I need to refer to both an original workbook and the current workbook, I
create two Public variables for the references and initialize them with the
workbook open event. I don't know if this will save you any time, however.
--
Gary's Student


"Jacob" wrote:

> I suppose a better question would be: is there a way to associate the
> workbook with the userform and all its contents and actions regardless
> of the file name?
>
>
> On Nov 9, 1:57 pm, "Jacob" <jlong...@gmail.com> wrote:
> > thanks for your help. that should work, but now i am realizing that
> > there are a lot of other actions that need the original workbook to be
> > active. it seems silly to place this everywhere where there is
> > interaction. It seems that it would be best to some how activate the
> > workbook whenever that particular userform is being used. is there a
> > way to do this?
> >
> > On Nov 9, 12:25 pm, Gary''s Student
> >
> > <GarysStud...@discussions.microsoft.com> wrote:
> > > The problem may be that you are using a constant for the filename. Once the
> > > file has been save with a new name then:

> >
> > > Dim s As String
> > > s = Selection.Worksheet.Parent.Name

> >
> > > should represent the latest filename. Then:

> >
> > > Set WB1 = Workbooks(s)
> > > --
> > > Gary's Student

> >
> > > "Jacob" wrote:
> > > > my program runs from a userform and uses one workbook. there is a link
> > > > on the userform, however, that can open another workbook. if this
> > > > other workbook is opened, the userform will interact with that workbook
> > > > since it is the active one. I need the original workbook to be
> > > > activated before manipulating the form again. I was able to solve this
> > > > using the following code in every section that referred to the original
> > > > workbook:

> >
> > > > Dim WB1 As Workbook
> > > > Set WB1 = Workbooks("<filename>.xls")
> > > > WB1.Activate

> >
> > > > I then realized that I have a save as button on the userform and the
> > > > workbook will often be saved with a different name rendering the above
> > > > code useless, or worse. is there a way around this? thanks.

>
>

 
Reply With Quote
 
Jacob
Guest
Posts: n/a
 
      10th Nov 2006
Thanks for your help. I'm not sure if that is what I need though. I
started a new thread after doing a little brainstorming. I still don't
know the best way to go about this.

http://groups-beta.google.com/group/...353d9a9ca0faf5


On Nov 9, 3:43 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> I don't know.
>
> If I need to refer to both an original workbook and the current workbook, I
> create two Public variables for the references and initialize them with the
> workbook open event. I don't know if this will save you any time, however.
> --
> Gary's Student
>
> "Jacob" wrote:
> > I suppose a better question would be: is there a way to associate the
> > workbook with the userform and all its contents and actions regardless
> > of the file name?

>
> > On Nov 9, 1:57 pm, "Jacob" <jlong...@gmail.com> wrote:
> > > thanks for your help. that should work, but now i am realizing that
> > > there are a lot of other actions that need the original workbook to be
> > > active. it seems silly to place this everywhere where there is
> > > interaction. It seems that it would be best to some how activate the
> > > workbook whenever that particular userform is being used. is there a
> > > way to do this?

>
> > > On Nov 9, 12:25 pm, Gary''s Student

>
> > > <GarysStud...@discussions.microsoft.com> wrote:
> > > > The problem may be that you are using a constant for the filename. Once the
> > > > file has been save with a new name then:

>
> > > > Dim s As String
> > > > s = Selection.Worksheet.Parent.Name

>
> > > > should represent the latest filename. Then:

>
> > > > Set WB1 = Workbooks(s)
> > > > --
> > > > Gary's Student

>
> > > > "Jacob" wrote:
> > > > > my program runs from a userform and uses one workbook. there is a link
> > > > > on the userform, however, that can open another workbook. if this
> > > > > other workbook is opened, the userform will interact with that workbook
> > > > > since it is the active one. I need the original workbook to be
> > > > > activated before manipulating the form again. I was able to solve this
> > > > > using the following code in every section that referred to the original
> > > > > workbook:

>
> > > > > Dim WB1 As Workbook
> > > > > Set WB1 = Workbooks("<filename>.xls")
> > > > > WB1.Activate

>
> > > > > I then realized that I have a save as button on the userform and the
> > > > > workbook will often be saved with a different name rendering the above
> > > > > code useless, or worse. is there a way around this? thanks.


 
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
Bring focus to same cell every time opened?? Rita Brasher Microsoft Excel Misc 2 18th Jul 2008 05:57 PM
How to bring flash embedded in a html to focus? Krupa Microsoft Dot NET Compact Framework 0 12th Jun 2006 05:18 PM
Bring Main Window of a Process To Focus James Hancock Microsoft Dot NET Framework 2 1st Apr 2004 06:45 AM
How to bring window with current focus to front Jeff Windows XP Customization 1 2nd Oct 2003 08:01 PM
bring focus to form element using VB .NET 2003 John Microsoft Dot NET 0 1st Aug 2003 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 PM.