+ Reply to Thread
Results 1 to 17 of 17

Macro to open file on computer

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Macro to open file on computer

    What code would I use to open a file called Camera Log Backup.app located in the same directory as the Workbook?

    I am using Excel 2011 on a mac.

  2. #2
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello
    There are 2 things to do.
    1. enter your code in the Open Workbook event of the workbook (go to macro editor and select "thisWorkbook" on the tree view and change the event dropdown to see "Open"). This should place the header of Private Sub Workbook_Open() in the space
    2. not sure of the type of your file, and what you plan to do with its contents ?
    Please Login or Register  to view this content.
    Regards
    Most helpful to mark solved items as such (see help for directions). Star ratings are always welcome.

  3. #3
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    Its basically just an apple script that I want to run from a macro in Excel. The script just runs in the background and does its thing then exits. I just need the excel macro to trigger it form the Spreadsheet.

  4. #4
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello

    My code opens the file, not runs it.

    So you need to use the SHELL() function like :
    Replace my code (in same place) with
    Please Login or Register  to view this content.
    Regards

  5. #5
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    Sorry im a little confused. Is this what the code should be:

    Please Login or Register  to view this content.
    Because that gave me the error 'Invalid Outside Procedure'

  6. #6
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Sorry I should have been clearer.
    The OPEN will open the file to examine its contents.
    The SHELL will run the file without opening it.

    So remove lines 2 and 3 and keep 1

  7. #7
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    So this is the code I entered:
    Please Login or Register  to view this content.
    It gives me 'Run Time Error 53 - file not found'
    I have the file in the same location as the workbook. I tried putting it in the root directory of my HD incase it was looking there instead but it still didnt work. (i would like to keep the file in the same directory as the workbook if possible)

  8. #8
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello
    It may need an absolute path reference, so I tested with creating an .exe (Windows) and putting it on my folder : D:\Documents\Excel\test.exe

    It ran this file with the code:
    Please Login or Register  to view this content.
    So try to add the full path, it does not seems to work on relative path references.

    Regards

  9. #9
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    I tried this, which is the Mac equivilant of C:\
    Please Login or Register  to view this content.
    Im still getting error 53.
    I have the file in my root directory.

  10. #10
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello
    I researched this a bit and it does not always seem that Shell() works properly on the Mac. Some people suggest Macscript() which is pretty similar but runs Mac scripts - which may be in line with your intentions.

    So replace the Shell() with Macscript(), just comfirm in your help that the parameters are the same, I think so.

    Regards

  11. #11
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    I changed it to:

    temp = MacScript("/Camera Log Backup.app")

    But I get a run time 5 error.

  12. #12
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello
    Its a pretty meaningless error, perhaps it is struggling with finding the file.
    Replace your MacScript line with something like this
    Please Login or Register  to view this content.
    So the logic is to attempt with your file path and name. It attempts to confirm if it can find it with the Dir function.
    If not good, it should open a dialog to manually find your file and then replace the file name and path with the manually extracted details and then run the script.

    I can't really test if that will work on your Mac though so you will have to provide feedback

    Regards

  13. #13
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    This time I got a 1004 run time error, with the following line highlighted:

    correctFile = Application.GetOpenFilename("Text Files (*.app), *.app") 'not found, open dialog for manually search

  14. #14
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to open file on computer

    Are you allowing for the Mac's different path separator?

    i.e. : rather than \
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  15. #15
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    I am, I changed it to :

  16. #16
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Macro to open file on computer

    Hello
    My suggestion is to re-post the question, I can't test the code (don't have a Mac) so I can't provide guaranteed working code. You could also try to search for the specific error message in a search engine and see if there are suggestions to overcome those.
    Best of luck

  17. #17
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Macro to open file on computer

    Will do, thanks for you help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to open a file on Dropbox from any computer
    By ricdamiani in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-30-2013, 02:48 AM
  2. Macro to open a file on dropbox from any computer
    By skip2mylew in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2013, 06:03 PM
  3. Open file from another computer with different username/password
    By nknutson13 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2012, 08:13 AM
  4. Open mdb file from another computer
    By stefantem in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-25-2006, 08:29 AM
  5. [SOLVED] How do I open an xls file if I don't have Excel on my computer?
    By M. klimo in forum Excel General
    Replies: 2
    Last Post: 11-04-2005, 09:40 PM

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