+ Reply to Thread
Results 1 to 7 of 7

Macro in xlma not working from time to time

  1. #1
    Registered User
    Join Date
    07-25-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Macro in xlma not working from time to time

    Hello everybody,

    I have a problem with the following macro:

    Sub get_f_data()

    Dim path As Variant
    Dim excelfile As Variant
    path = "C:\Users\me\Desktop\get_f_data\"

    excelfile = Dir("*.xls")

    Do While excelfile <> ""

    Workbooks.Open fileName:=path & excelfile

    Call project_capacity
    Call electricity_production

    excelfile = Dir

    Loop

    End Sub


    It's an xlma file that I launch from the Excel task bar. It opens all workbook in the folder get_f_data and launches the procedures project_capacity and electricity_production.

    Sometimes it's working fine, and sometimes when I click on the button in the taskbar that is linked to the xlma nothing happen. I have no error message but nothing happen, no file is opened.

    Sometimes after opending different files and running other macros, this macro tries to open files outside the designated folder.

    Could you please help me with this? Does anybody have an idea on why it's not working sometimes?

    Thank you for your help;
    Last edited by noemiemich; 07-25-2010 at 12:36 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro in xlma not working from time to time

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-25-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro in xlma not working from time to time

    Hello,

    Sorry about that. Here is the message with the codes tags:

    Hello everybody,

    I have a problem with the following macro:

    Please Login or Register  to view this content.
    It's an xlma file that I launch from the Excel task bar. It opens all workbook in the folder get_f_data and launches the procedures project_capacity and electricity_production.

    Sometimes it's working fine, and sometimes when I click on the button in the taskbar that is linked to the xlma nothing happen. I have no error message but nothing happen, no file is opened.

    Sometimes after opending different files and running other macros, this macro tries to open files outside the designated folder.

    Could you please help me with this? Does anybody have an idea on why it's not working sometimes?

    Thank you for your help;
    Edit/Delete Message

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro in xlma not working from time to time

    You should just edit the first post

    Why are you declaring Path as a variant instead of a string?
    Likewise excelfile

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro in xlma not working from time to time

    This
    Please Login or Register  to view this content.
    looks for xls files in the current directory, which may be different from one time to the next. Try instead this:

    Please Login or Register  to view this content.
    That code leaves all those files open ...
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    07-25-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro in xlma not working from time to time

    Hello,

    Thank you very much for your help.

    royUK, I found the code on the net and I used it as it was, I don't relly know why "variant" is used instead of "string" in this macro.

    Shg, thank you very much for your new code, it seems to be working find now.

    Thank you very much!

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro in xlma not working from time to time

    You might also want to use *.xlsm & *.xlsx to allow for different file extensions

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1