Window Activation through a passed variable.

MarkES

New Member
Joined
Apr 11, 2010
Messages
8
Hi All,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I was wondering if you could help me with the below.
<o:p></o:p>
I have a VBA project with 2 modules.
<o:p></o:p>
Module 1 opens 2 workbooks; 1 based off user input from an input box by taking the user input and concatenating it with the desired file path and opening a second file from a different file path in a difference location. (not really too important).
<o:p></o:p>
For example: user input might be 585006 and this is assigned to the variable “Fund”.
<o:p></o:p>
There is another variable “Tax” which is assigned the value(constant) “BT” so the concatenation would be 585006BT which is assigned to the variable “filename” and when concatenating with the variable “Filepath” opens the workbook named 585006BT.
<o:p></o:p>
This works fine and will open the workbook called 585006BT.xls and also opens the other workbook required as well.
<o:p></o:p>

“Workbooks.Open Filepath & Filename”<o:p></o:p>


C:\blah|blah\585006BT.xls<o:p></o:p>

<o:p></o:p>
I then pass the variable: essentially variable “Fund” and variable “Tax” to the variable “Feederfund” to be called from Module 2.
<o:p></o:p>
Note I have also declared “feederfund” as public in Module 1 so it can be passed to Module 2, to the variable “taxfile”
<o:p></o:p>
Module 2 for me is supposed to flick between 585006BT.xls and the other workbook as required. I want to use the variable “taxfile” to activate the window for the workbook it represents.
<o:p></o:p>
For example the code as it’s working now is :
<o:p></o:p>

Windows("585006BT.xls").Activate,<o:p></o:p>

<o:p></o:p>
I think the code should be something like
<o:p></o:p>

Windows(“taxfile”).activate<o:p></o:p>


<o:p></o:p>

<o:p></o:p>
Where (“585006BT.xls”) is hardcoded (basically I recorded opening this file.) What I want to do is to be able to activate the file (585006BT.xls) based off the variable “taxfile” because the input box in module 1 will be used to select different files.
<o:p></o:p>
“taxfile” and “585006BT.xls” are basically the same thing. I can see that the taxfile value is 585006BT by hovering over it during the step through. I also know that windows is an object and maybe I’m not treating that correctly.
<o:p></o:p>
As an aside I will be working on a for each….next loop, to loop through a series of files instead of the input box but for now I’d to get the window to activate via variable rather than hardcoding as I’ll end up needing it eventually anyway.
<o:p></o:p>
I know this might seem like some sloppy coding but I guess us beginners tend to do things the hard way natch: inefficient when starting out.

Thanks for your help
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I didn't really follow your description but if "taxfile" (in the below statement) is a variable, it should not be in quotes. The quotes make it a literal and equal to the word "taxfile" not the contents of the variable named "taxfile".

Windows(“taxfile”).activate

Gary
 
Upvote 0
Yes, I know that was a bit of a convaluted explaination, but you hit it on the head, that worked perfectly, I thought I tried every combo, but obviously not....

undone by bleedin' quotation marks - who'd a thunk it!!

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top