+ Reply to Thread
Results 1 to 12 of 12

VBA Programming in Excel

  1. #1
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    VBA Programming in Excel

    Hi All,

    Hope you can help with some Excel VBA

    I'm trying to build a Macro to retrieve the File Path of a file that is within a specified Folder Path that is currently in Cell A1 ( Full Folder path is in Cell A1) and place the retrieved file path within B1 ( There will only ever be 1no. file with the folder at any one time).

    then do the same for A2 with the File path in B2 etc. ( note : The folder path in A2 will be different to A1 and then hence will be a different File path in B2)

    I have approximately 500 Rows within excel to do this with.

    I have tried some coding myself and happy to share but i do feel I'm already heading down the wrong road.

    Hope i have managed to explain this correctly and many thanks in advance for any help.

    Thanks

    Juicy2052

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    Read the yellow banner at the top to attach an example without personal data.
    Include a before and after.
    Experience trumps academics every day of the week and twice on Sunday.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    If you have only 1 file in each folder and the path in Column A has no drive letter, but the folder is in C, then this does it.
    Please Login or Register  to view this content.
    If the drive letter is included in the path in Column A, change this line
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    If you want to refer to excel type file, change to
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA Programming in Excel

    Hello Jolivanes,

    That works a treat, but i was trying to retrieve the File path in B2 etc. rather than the file name.

    The drive letter is included within Column A and I'm actually the file type is a pdf

    What would i need to change to retrieve the file path ?

    Thanks

    Juicy2052

  5. #5
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA Programming in Excel

    Hi Jolivanes

    Just to clarify

    The path in Column A is the Folder Path and I'm looking for the File Path that is in side the Folder of Column A to be put in column B


    Many Thanks

    Juicy2052

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    Give us some examples. See Post #2 again

  7. #7
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA Programming in Excel

    Hi Jolivanes

    Hopefully i have done this correct and I should of uploaded the example workbook.

    I can get the file path by the way of a manual search ie. through Dialog but the idea is to have the folder path in one column and the File path of the file inside the folder in another column.

    Then hyperlinks will be created to each location etc.

    Hope this helps

    Juicy 2052
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    Is this what you have in mind?
    Please Login or Register  to view this content.
    If you get a security warning, read microsoft's reply here.
    https://answers.microsoft.com/en-us/...7-9ee79f56a201

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    You don't need to change the data in Column I if you don't want to. It might keep things clearer.
    You can do that in the code.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA Programming in Excel

    Hi Jolivanes

    Yes that's what I'm looking for combined with your previous code so i have now the below which runs perfectly in the Test File, however, as soon as i apply and run in the actual file i get a Run-time error 5, Invalid procedure call or argument ?

    HTML Code: 

    The piece of code causing the issue is the two lines of Hyperlink Code as below, In the actual file its running through 243 Rows.

    HTML Code: 
    I like the idea of always inserting the Hyperlinks as it always refreshes the link, the file will be replaced say once a year and may be a different file Name etc. , the folder will always remain.

    Why do you think im getting the run-time error 5 ?

  11. #11
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA Programming in Excel

    Hi Jolivanes

    Yes that's what I'm looking for combined with your previous code so i have now the below which runs perfectly in the Test File, however, as soon as i apply and run in the actual file i get a Run-time error 5, Invalid procedure call or argument ?

    Please Login or Register  to view this content.
    The piece of code causing the issue is the two lines of Hyperlink Code as below, In the actual file its running through 243 Rows.

    Please Login or Register  to view this content.
    I like the idea of always inserting the Hyperlinks as it always refreshes the link, the file will be replaced say once a year and may be a different file Name etc. , the folder will always remain.

    Why do you think im getting the run-time error 5 ?

  12. #12
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Programming in Excel

    I don't have your actual file so it's guesswork.
    Do all offset cells used in the macro have values in the cells and do all the Folders (Column D) and Files (Column I) exist?

+ 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] Programming in excel
    By shah.ghazanfar in forum Excel General
    Replies: 2
    Last Post: 06-10-2022, 03:25 PM
  2. Excel VBA Programming?
    By loydchase in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2018, 03:08 AM
  3. New to VBA Programming for Excel
    By gmr4evr1 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 11-24-2014, 08:04 PM
  4. New to Excel Programming
    By congee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2013, 06:17 PM
  5. Replies: 1
    Last Post: 08-20-2012, 01:13 PM
  6. Excel programming
    By rksvba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2009, 08:05 AM
  7. Excel Programming
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2006, 04:10 AM

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