Consulting

Results 1 to 7 of 7

Thread: open xlsm vs. xls

  1. #1
    VBAX Regular
    Joined
    Nov 2009
    Posts
    6
    Location

    Question open xlsm vs. xls [SOLVED]

    Hi all,

    I have a code where i need to open a other workbook. I works fine with .xls files, but when im trying to open a .xlsm file i just get a error? Anyone knows why?

     
    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim pw            As String
    Dim path            As String
    Dim clor            As String
     
    Application.ScreenUpdating = False
     
    With ListBox1
    For i = 0 To .ListCount - 1
    If .ListIndex = i Then pw = Range("B" & i + 4).Value
    If .ListIndex = i Then path = Range("G" & i + 4).Value
    If .ListIndex = i Then clor = Range("I" & i + 4).Select
    Next i
    End With
     
    'ERROR COMES HERE!
        Application.Workbooks.Open Filename:=path
    Last edited by maxkoy; 11-30-2009 at 12:36 PM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Are you working in Excel 2007?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Nov 2009
    Posts
    6
    Location
    Yes its excel 2007 im using.

    in advance thanks!!
    Last edited by maxkoy; 11-30-2009 at 08:16 AM.

  4. #4
    VBAX Regular
    Joined
    Nov 2009
    Posts
    6
    Location
    its error 1004 i get. And the debug mode marks this line
    "Application.Workbooks.Open Filename:=path"

  5. #5
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Can you supply a sample workbook?, there really shouldn't be a difference in opening xls or xlsm as xl2007 will use compatability mode as needed, it must be something else.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Wouldn't your code be better served as

    [vba]

    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim pw As String
    Dim path As String
    Dim clor As String

    Application.ScreenUpdating = False

    With ListBox1

    pw = Range("B" & .ListIndex + 4).Value
    path = Range("G" & .ListIndex + 4).Value
    clor = Range("I" & .ListIndex + 4).Select
    End With

    Application.Workbooks.Open Filename:=path
    [/vba]

    What does the variable path contain when it fails?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Nov 2009
    Posts
    6
    Location
    I just changed the macro settings in excel and i think it did the job.

    xld I think you may be right! Will try to use that code i stead

Posting Permissions

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