• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Windows(filename).Activate Discrepancy

Jason F

New Member
Hello,

I have a mystery on my hands.

I wrote a macro that involves opening another excel file, then activating it using

Code:
    'Activate Data Log workbook
    Windows(filename).Activate

When I run this code, filename is the name of an excel file EXCLUDING .xls, and it runs just fine! I then sent the macro to a friend of mine, and it wouldn't work for him. We eventually got it to work but had to add .xls to the filename:

Code:
    'Activate Data Log workbook
    Windows(filename & ".xls").Activate

Why would the original code have worked on my computer but not his?

Thanks!
Jason F.
 
Also, I would think it should be:
Workbooks(...).Activate
not Windows...just another possibility.
 
Hi Deepak,

The filename is "Test #3, -0091- restart2013Oct11.0338PM". It is the exact same filename that I used.
 
Hi Deepak,

The filename is "Test #3, -0091- restart2013Oct11.0338PM". It is the exact same filename that I used.


Then where the extension{.xls} of the file.

Code:
Workbooks("ABCD.xls").Activate
or
Windows("ABCD.xls").Activate

OR

Code:
filename = "ABCD.xls"
Workbooks(filename).Activate
or
Windows(filename).Activate
 
The file extension is never defined. To double check this, I added the following bit of code to my macro

Code:
    Debug.Print (fileArray(I))
    Windows(fileArray(I)).Activate

The Debug.Print command returns "Test #3, -0091- restart2013Oct11.0338PM" - No extension! At this point I'm surprised that my code runs at all.

When I use my friend's computer, I have to add the ".xls" extension as I mentioned in my first post to get the macro to run, which seems to make more sense.
 
Hi Jason ,

Windows has a Tools , Folder Options setting called :

Hide file extensions for known file types

If this is checked , then when you open any Excel file you might have seen that the extensions are not displayed , whereas if that option is not checked , then the file extensions are displayed.

It is possible this setting differs on your and your friend's computers.

Narayan
 
I think Narayan has solved it, I now remember running into this problem myself.
 
Yes, that is it. I checked with him and he does not have that option checked. Code ran fine when he checked it.

Thank you!
 
Back
Top