Results 1 to 15 of 15
  1. #1
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15

    Open excel 2007

    Hi,

    I have created a macro and code to open an excel file. However, my system at work is running both excel 2003 and 2007. I want the file to open in excel 2007 however it keeps opening in 2003 and then converting it.

    I am running access 2007. The code is below:

    Public Function Workbook_Open()



    Dim appExcel As Object
    Set appExcel = CreateObject("Excel.Application")
    appExcel.workbooks.Open "T:\IT Dept\Teacher Resources\Records\Year 9\Unit 1 records 07 entry MAIN.xlsx"
    appExcel.Visible = True

    End Function

    Any solutions, thanks,

    spqr

  2. #2
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    This could also be your OS being the problem.

    Could it be that you have set the Open as (when opening a normal Xslx file) to Excel 2003? You can change this with right click, open as and then check always use this option.

    Ps. Why do you have both installed?

  3. #3
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    Hi,

    The default is 2007.I work in a school and the network manager is running both because not all staff are able to use 2007 at the moment. Is there something I could put in the code that would force use of 2007? I know the path to the 2007 excel executable: "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"

    Thanks

  4. #4
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    You can use a shell function. See Shell in the help in Access for more info.

    This should solve the problem.

  5. #5
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    I have tried to use the shell function using the two methods below:

    Dim RetVal
    Dim Filename As String
    Filename = "T:\IT Dept\Teacher Resources\Records\Year 9\Unit 1 records 07 entry MAIN.xlsx"
    RetVal = Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE " & Filename, 1)

    OR

    Call Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE T:\IT Dept\Teacher Resources\Records\Year 9\Unit 1 records 07 entry MAIN.xlsx", vbNormalFocus)

    However, due to the spaces the files attempted to be opened are IT.xlsx Dept\Teacher.xlsx etc.

    How can I avoid this error?

  6. #6
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    I thought that using the %20 instead of the spaces should solve it.

  7. #7
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    Get a file not found error now.

  8. #8
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    Can you post the current code?

  9. #9
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    Dim RetVal
    Dim Filename As String
    Filename = "T:\IT%20Dept\Teacher%20Resources\Records\Year%209 \Unit%201%20records%2007%20entry%20MAIN.xlsx"
    RetVal = Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE " & Filename, 1)

  10. #10
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    Quote Originally Posted by spqr View Post
    Dim RetVal
    Dim Filename As String
    Filename = "T:\IT%20Dept\Teacher%20Resources\Records\Year%209 \Unit%201%20records%2007%20entry%20MAIN.xlsx"
    RetVal = Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE " & Filename, 1)
    Your filename has a space after year 209, did you directly copy and paste it? if you delete the space it should be cleared.

  11. #11
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    I copied it exactly and checked, no spaces.

  12. #12
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    Try this:
    Shell("""C:\Program Files\Microsoft Office\Office12\EXCEL.EXE """ & Filename & """, 1)
    You can delete all the %20 in the file name this way.

    Before you try check if there really is no space:
    Filename = "T:\IT%20Dept\Teacher%20Resources\Records\Year %209_\Unit%201%20records%2007%20entry%20MAIN.xlsx"
    'The red line above shows the space in your posted code.

  13. #13
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    checked for spaces none must have been pasted strangely. I think when I past it in this little box a carriage return or space is automatically entered.
    Filename = "T:\IT%20Dept\Teacher%20Resources\Records\Year%209 \Unit%201%20records%2007%20entry%20MAIN.xlsx"

    I get a syntax error with the new code you supplied.

  14. #14
    spqr is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    15
    I got it working using this:

    Call Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE ""T:\IT Dept\Teacher Resources\Records\Year 9\Unit 1 records 07 entry MAIN.xlsx""", vbNormalFocus)


    Thanks for your help.

  15. #15
    Jamy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    36
    No Problem.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. 2007 MDE will not Open in Access 2003
    By wmecook in forum Programming
    Replies: 4
    Last Post: 12-01-2009, 05:15 PM
  2. Replies: 0
    Last Post: 11-17-2009, 02:35 PM
  3. What Database is Open? (Access 2007)
    By jhrBanker in forum Access
    Replies: 3
    Last Post: 06-06-2009, 09:00 AM
  4. Replies: 1
    Last Post: 06-02-2009, 04:29 PM
  5. Open Excel from within Access?
    By kjw in forum Access
    Replies: 2
    Last Post: 04-08-2008, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums