+ Reply to Thread
Results 1 to 15 of 15

VBA for opening certain file, NOT just a file location

  1. #1
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Question VBA for opening certain file, NOT just a file location

    I have a spread sheet with rollover hyperlinks to change cells certain colours when the mouse hovers over them. I also have a script which allows me to double click on a cell which makes it open a file location so the user can choose which (or multiple) files to open.

    however. when I try to add the actual file name on the end of the file destination it doesn't seem to accept it. my code is shown below. what am I doing wrong?

    I have attached the spread sheet and shown code below




    Please Login or Register  to view this content.
    when I try to add a file name after the "C:\users\boymam\desktop" It doesn't work, either im added wrong or the codes wrong? if someone could show me how to add the actual file id appreciate it,

    thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    One possible solution wuld be to enable it to differentiate between files and folders. One possible method would be that if in 'ChDir' there is a fullstop, then it is most likely a file extension.

    Please Login or Register  to view this content.
    Hope this helps.
    Last edited by TKCZBW; 04-25-2014 at 04:12 AM. Reason: appaling grammar

  3. #3
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    sorry a little confused. could you be kind enough to place that into my code to show me where to add that

  4. #4
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    Please Login or Register  to view this content.
    If it's directed to a folder it will execute the code you provided (I have't checked this so I assume your code already works for folders), if it's a file (or rather has a file extension), then it will just directly open the file. Is that long the lines of what you were looking for?

  5. #5
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    yeah my code works. I will try this out in a minute. thanks

  6. #6
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    I either having a bad morning or im a **** lol ..cos im still confused.

    how would that code look if you forget the option to open a folder and JUST have it directly open this file upon double click

    C:\Users\boymam\Desktop\Graphics

    this is the destination folder.. IN that folder there is a picture simply named "2". being dumb as I am. I am trying to simply do this

    C:\Users\boymam\Desktop\Graphics\2 or .2 or "2"

    can you please show the whole formula for that? because im doing something stupid I know it

  7. #7
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    Hmm.

    The file won't simply be named '2', it will be 2.png or have some other file extension appended to it (you might need to go into properties).

  8. #8
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    OH YEAH... GOD im stupid lol its Friday, forgive me lol

  9. #9
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    im so sorry mate, but still wont work. file is called 2.png

    I tried to just add that to the end of the destination but wont work.

  10. #10
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    Is an error coming up or is it just not doing anything?

  11. #11
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    I'm an idiot. An utter idiot. Since when has a PNG file been a workbook?

    You're right, it is friday!

  12. #12
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    says the path isn't found. which implies im getting the name of the file wrong but im not.. I must be added it wrong.

    im simply doing this.

    C:\Users\boymam\desktop\graphics and adding 2.png like so
    C:\users\boymam\desktop\graphics\2.png

    but do I have to do it differently? such as graphics.2.png graphics\"2.png" etc??

  13. #13
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    its almost as if the code I have is only designed to open FOLDERS and not the files themselves. so it doesn't recognise it.

  14. #14
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: VBA for opening certain file, NOT just a file location

    THe problem is we're using the workbooks.open command to open a non-workbook! If you try it on an excel file it wil work perfectly. I have to leave the office for a while now, but later I can set it to open a generic 'file' rather than just a workbook if you want.

  15. #15
    Forum Contributor
    Join Date
    04-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: VBA for opening certain file, NOT just a file location

    that would be perfect mate. cheers for help. im leaving at 12 today anyway. so prob continue this monday

+ 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. Save as macro that specifies file type, file location and takes file name from three cells
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-13-2013, 10:09 PM
  2. Replies: 1
    Last Post: 10-01-2012, 11:46 PM
  3. Opening file message when opening a file from an http address
    By The_Real_MerlinXL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2010, 12:33 PM
  4. opening a file from a remote location
    By Josh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2006, 05:10 PM
  5. [SOLVED] opening an excel file opens a duplicate file of the same file
    By skm in forum Excel General
    Replies: 1
    Last Post: 12-07-2005, 01:55 PM

Tags for this Thread

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