+ Reply to Thread
Results 1 to 21 of 21

Create a Macro to look at one cell and then open File

  1. #1
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Create a Macro to look at one cell and then open File

    Hello,

    I am working on creating a Macro to look in column D for the word "Monday". If the cell says Monday then I want it to open the link in the cell beside it. Is this possible?

    Example

    Column C Column D
    (Link to file) Monday
    (Link to file) Monday
    (Link to file) Tuesday

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Create a Macro to look at one cell and then open File

    should be possible, can you provide a sample link that you would be opening? Are you opening files that are local to your pc or network?
    Also in your image above, you have 2 monday's listed, so are you wanting to open both at the same time..

  3. #3
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Yes the files are on my network. Yes I want it to open all files with the corresponding day. So if it says Monday, I want the macro to open all files labeled for Monday.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Create a Macro to look at one cell and then open File

    Another few questions..
    How do you normally do this now without the macro? Do you simply click each link to open them?

    Does this list change in size? Will you ever have more than 15 files?
    (This one is just to see if the locations will change or if the ranges can be specifically set in the code)

    Are you wanting to simply chose a weekday and have it open the files? or you want it to automatically open the files based on "todays" date when you open the workbook that has the links in it?
    (So in other words, since today is Wednesday, when you open your file, the macro runs and determines today is wed and automatically opens the files for Wed.)

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to your attachment a VBA demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
             
    Dim oH As Hyperlink
        
    For Each oH In Hyperlinks
              
    If oH.Range.Cells(12).Text "Monday" Then If Dir(oH.Address) > "" Then Workbooks.Open oH.Address
        Next
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-14-2021 at 10:04 AM.

  6. #6
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Quote Originally Posted by cubangt View Post
    Another few questions..
    How do you normally do this now without the macro? Do you simply click each link to open them?

    Yes

    Does this list change in size? Will you ever have more than 15 files?
    (This one is just to see if the locations will change or if the ranges can be specifically set in the code)

    Yes it could be more

    Are you wanting to simply chose a weekday and have it open the files? or you want it to automatically open the files based on "todays" date when you open the workbook that has the links in it?
    (So in other words, since today is Wednesday, when you open your file, the macro runs and determines today is wed and automatically opens the files for Wed.)
    Yes choosing a weekday would be great. No I don't want it to open when I open workbook as I am not always working on this tab.

  7. #7
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    This did not work, runtime error.
    Attached Images Attached Images

  8. #8
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Create a Macro to look at one cell and then open File

    Give this a try, i setup and got working the Monday Button, you can update the others accordingly
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Create a Macro to look at one cell and then open File


    Quote Originally Posted by mlott3528 View Post
    This did not work, runtime error.
    As it well works on my side but the code must be located into the worksheet module …

  10. #10
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Thank you,

    I added it to my original workbook and updated it. I am still getting a runtime error, can you review my attachment and code.
    Attached Images Attached Images
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Create a Macro to look at one cell and then open File


    Obviously as the cell C2 does not contain a valid workbook reference …

  12. #12
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    I am sorry, I do not understand. What do I need to change it too?

  13. #13
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Create a Macro to look at one cell and then open File

    Quote Originally Posted by mlott3528 View Post
    Thank you,

    I added it to my original workbook and updated it. I am still getting a runtime error, can you review my attachment and code.
    That module should be removed, sorry about that..
    Everything is within the "Sheet1" object

    You can remove the Module1 all together.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Create a Macro to look at one cell and then open File

    Quote Originally Posted by mlott3528 View Post
    I am sorry, I do not understand. What do I need to change it too?
    Just paste my code as it is (as your mod was very not a great idea !) to the Sheet1 (Account Info) worksheet module

  15. #15
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Marc,

    Ok it worked in the template I gave you however in my original workbook it is not working and I know it is because my data is in different columns. Please see my attached template and advise.
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Create a Macro to look at one cell and then open File


    As the day is still in the next column of the hyperlink so there is nothing to change …

  17. #17
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Then why is it not working?

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Create a Macro to look at one cell and then open File


    If you click on the hyperlink in D3, does it open the expected workbook ?

  19. #19
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    Yes I can. But when I click run on the macro nothing happens.

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Create a Macro to look at one cell and then open File


    It seems an issue between your links on a network and the VBA Dir function so remove the If Dir(… part
    in order to directly open the workbook without any verification if it exists …

  21. #21
    Registered User
    Join Date
    03-25-2021
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    44

    Re: Create a Macro to look at one cell and then open File

    It just does not work.

    Anyone who can 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] VBA to Create hyperlink in respective cell to open saved file
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2014, 04:08 PM
  2. [SOLVED] Macro/VB code to open a file specified in cell
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2013, 09:21 AM
  3. [SOLVED] How to set macro to open word file equal to cell contents of a specific cell
    By ligerdub in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2012, 02:39 PM
  4. Create macro to open selectable list then open file
    By mattmurdock in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-02-2012, 07:10 PM
  5. [Solved] macro to open a file or, on error, create a new file
    By mjj347 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2012, 01:51 PM
  6. Macro to open pdf file based on a cell value.
    By martin61 in forum Excel General
    Replies: 0
    Last Post: 12-15-2011, 11:48 PM
  7. Macro to open a file, input value into a cell, and run a macro from file
    By wkhor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2011, 03:00 AM
  8. Macro: open file, read data, create table, vlookup
    By doctorspears in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2011, 12:54 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