Consulting

Results 1 to 11 of 11

Thread: Excel Opening The Wrong File

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Excel Opening The Wrong File

    I am (still) running xl2003 and WinXP. Applications that have been running without problems for years are suddenly failing.

    In many applications, I open an Excel file using VBA from another MS Office program (Word, Outlook, etc) using trypically
        Dim xlappl      As Excel.Application
        Dim xlbook      As Excel.Workbook
        Dim xlbookname  As String
    
        xlbookname = "D:\SomeDir\SomeFileName.xls"
    
        Set xlappl = CreateObject("Excel.Application")
        Set xlbook = xlappl.Workbooks.Open (xlbookname, UpdateLinks = False)
    Regardless of what file I try to open, xlbook is set to Personal.xls

    Any thoughts?
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Are you sure that's the only workbook being opened? If so, is there any code in the Workbook_Open event of your personal macro workbook?
    Be as you wish to seem

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Do you mean that personal.xls is the only file open (Workbooks.Count = 1)

    OR

    Do you mean that xlbook.Name = "Personal.xls"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Any chance that "D:\SomeDir\SomeFileName.xls" was saved as Hidden or Mininized?

    Can you open "D:\SomeDir\SomeFileName.xls" using just Excel?

    "Wrong File" or "Not the Right File"? Personal.xlsm in XLSTART is normally opened but hidden
    Last edited by Paul_Hossler; 01-19-2015 at 10:20 AM. Reason: can't type
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    What about

    Sub M_snb()
       GetObject("D:\SomeDir\SomeFileName.xls").Windows(1).Visible = True
    End Sub

  6. #6
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Aflatoon View Post
    Are you sure that's the only workbook being opened? If so, is there any code in the Workbook_Open event of your personal macro workbook?
    There is no code in the Workbook_Open event of Personal.xls
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  7. #7
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by SamT View Post
    Do you mean that personal.xls is the only file open (Workbooks.Count = 1)

    OR

    Do you mean that xlbook.Name = "Personal.xls"
    The latter, i.e., xlbook.Name = "Personal.xls"
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  8. #8
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Paul_Hossler View Post
    Any chance that "D:\SomeDir\SomeFileName.xls" was saved as Hidden or Mininized?

    Can you open "D:\SomeDir\SomeFileName.xls" using just Excel?

    "Wrong File" or "Not the Right File"? Personal.xlsm in XLSTART is normally opened but hidden
    I have been testing this for several days. "D:\SomeDir\SomeFileName.xls" was not saved as hidden or minimized, etc.
    Yes, the file opens fine using just Excel and the files opens fine when opened from another open workbook. It is just when a non-Excel application tries to open any Excel file
    I am running xl2003, so the personal macro file is Personal.xls, not Personal.xlsm
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  9. #9
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Could you post a word doc with the code necessary to replicate the issue? Do you happen to have an 'On Error Resume Next' someplace before the snippet you posted in #1?

    Mark

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Did you test my suggestion as a macro in Word ?

  11. #11
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
     It is just when a non-Excel application tries to open any Excel file
    To be specific. Does this happen when all other applications you have that currently can open excel, do open Excel?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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