Hyperlink to Photos When Moving Files

  • Re: Hyperlink to Photos When Moving Files


    Ok - that at least made it run, but I got a runtime error "Cannot open the specified file". When I click "Debug", it shows me this line: ThisWorkbook.FollowHyperlink ThisWorkbook.Path & "\" & Folder & "\" & ImageName(Target)

    Should I have changed the "\" & Folder & "\" to my folder names?

  • Re: Hyperlink to Photos When Moving Files


    I can see that my code won't work, as it didn't take into account the "photos" folder either.

    Replace this:

    Code
    Sub ShowImage(Folder As String, Target As Range)
        ThisWorkbook.FollowHyperlink ThisWorkbook.Path & "\" & Folder & "\" & ImageName(Target)
    End Sub



    With this

    Code
    Sub ShowImage(Folder As String, Target As Range)
        ThisWorkbook.FollowHyperlink ThisWorkbook.Path & "\Photos\" & Folder & "\" & ImageName(Target)
    End Sub



    Tell me how that works

    Edit: No you don't have to change folder to your folder names as it is a variable which is defined based on one of your previous posts.

  • Re: Hyperlink to Photos When Moving Files


    I thought it was, which is why I originally didn't do that. I have now copied all of the individual photo sub-folders to the folder "Photos", so that they are not under another sub-folder.

    However, when I substituted the code lines above I'm back to it not running at all - obviously I'm doing something wrong.

  • Re: Hyperlink to Photos When Moving Files


    Ok - found out why it wouldn't run (Macros disabled), so enabled that - but still got the same runtime error as before. Debug takes me to the same line

  • Re: Hyperlink to Photos When Moving Files


    Can you give me the exact path of one of the folders (eg Mud Room). I just want to check if it's right.
    Is the Image name exactly "the tag number".jpg ?
    Could you please also double check that the folder names and abbreviations in the code correspond to each other?
    Cheers

    Attila

  • Re: Hyperlink to Photos When Moving Files


    The workbook path is as follows:

    C:\Users\Wayne\Desktop\Pacific Scirroco


    Path for photos is as follows (example):

    C:\Users\Wayne\Desktop\Pacific Scirroco\Photos\Acetylene Room (AR)

    A typical photo in this folder is named "AR-003.jpg".


    Think I just spotted the problem........ The photo folders are named, for example, "Acetylene Room (AR)" - but the code only specifies "Acetylene Room". Let me fix that and try again

  • Re: Hyperlink to Photos When Moving Files


    That must be it... I definitely hope so, because I'm running out of ideas lol

  • Re: Hyperlink to Photos When Moving Files


    LOL. Ok, that worked - but it opens up the folder where the photos are.... Was that what it was supposed to do? I thought it would open the photo associated with the particular item?

  • Re: Hyperlink to Photos When Moving Files


    I thought so too... But I forgot that we would need to specifiy the program to open it with.
    What do you want to use?
    Internet Explorer? That is something which exists on almost every windows PC, so you don't have to be worried that your client might not have it...

  • Re: Hyperlink to Photos When Moving Files


    That will work, or Windows Photo Viewer, either one. Photo Viewer gives them options to rotate, zoom in, etc

  • Re: Hyperlink to Photos When Moving Files


    Use this instead of the current show image sub:

    Code
    Sub ShowImage(Folder As String, Target As Range)
        Shell ("c:\windows\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen " & ThisWorkbook.Path  & "\Photos\" & Folder & "\" & ImageName(Target))
    End Sub



    That should work

    Regards

    Attila

  • Re: Hyperlink to Photos When Moving Files


    Works but opens the wrong photo - for each area it opens the 1st photo in the folder...... It also minimizes the photo - you can click to restore it of course.

  • Re: Hyperlink to Photos When Moving Files


    I have no idea why it minimizes, as I have specified ImageView_Fullscreen ...
    Can you do me a favor?
    comment out the line with Shell(xxxxx) by putting an apostrophe in front of the line ( ' )
    and add this line of code below it:

    Code
    MsgBox ThisWorkbook.Path  & "\Photos\" & Folder & "\" & ImageName(Target)


    Run the code and see if it returns the correct path of the image in the message box.

    Cheers

    Attila

  • Re: Hyperlink to Photos When Moving Files


    Gives me a pop-up window with the folder path name (C:\Users\Wayne\Desktop\Pacific Scirocco\Photos\Ballast Pump Room (BP)\

  • Re: Hyperlink to Photos When Moving Files


    Thanks... that means that the part which puts the filename together isn't working the way we want it to.

    Could you please post the code you have at the moment?

  • Re: Hyperlink to Photos When Moving Files


    That's kind of what I figured, but don't know enough about code to realize why...... I suppose it doesn't help that the file name is spread over 3 columns and has to be compiled by the code.

  • Re: Hyperlink to Photos When Moving Files


    Would it be because the "TagNo" line includes the .jpg? That's the photo name, but not the item name..........

  • Re: Hyperlink to Photos When Moving Files


    That shouldn't be an issue as it is one of the most basic functionalities of vba.
    Could you quickly pop me the code?
    Cheers

  • Re: Hyperlink to Photos When Moving Files


    That line has to include the .jpg as we are reffering to the image to open it.

  • Re: Hyperlink to Photos When Moving Files


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column <> Range("N1").Column Or IsEmpty(Target) Then Exit Sub
    Select Case Range("A" & Target.Row).Value
    Case "AR"
    ShowImage "Acetylene Room (AR)", Target
    Case "BP"
    ShowImage "Ballast Pump Room (BP)", Target
    Case "BPV"
    ShowImage "Ballast Pump Vent Room (BPV)", Target
    Case "BL1"
    ShowImage "Battery Locker 1 (BL1)", Target
    Case "BL2"
    ShowImage "Battery Locker 2 (BL2)", Target
    Case "BS"
    ShowImage "Bulk Storage Area (BS)", Target
    Case "BSV"
    ShowImage "Bulk Storage Room Vent (BSV)", Target
    Case "DF"
    ShowImage "Drill Floor (DF)", Target
    Case "HR"
    ShowImage "Heli Fuel System (HR)", Target
    Case "HL"
    ShowImage "Helideck (HL)", Target
    Case "MP"
    ShowImage "Moonpool (MP)", Target
    Case "MPR"
    ShowImage "Mud Pit Room (MPR)", Target
    Case "MPM"
    ShowImage "Mud Process Module (MPM)", Target
    Case "MRT"
    ShowImage "Mud Reserve Tank (MRT)", Target
    Case "MRV"
    ShowImage "Mud Reserve Tank Vent (MRV)", Target
    Case "OXY"
    ShowImage "OXY Room (OXY)", Target
    Case "PL"
    ShowImage "Paint Locker (PL)", Target
    Case "SS"
    ShowImage "Shale Shakers (SS)", Target
    Case "WT"
    ShowImage "Well Test Area (WT)", Target
    End Select
    End Sub
    Sub ShowImage(Folder As String, Target As Range)
    'Shell ("c:\windows\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen " & ThisWorkbook.Path & "\Photos\" & Folder & "\" & ImageName(Target))
    MsgBox ThisWorkbook.Path & "\Photos\" & Folder & "\" & ImageName(Target)
    End Sub
    Function ImageName(Target As Range) As String
    TagNo = Range("A" & Target.Row).Value & Range("B" & Target.Row).Value & Range("C" & Target.Row).Value & ".jpg"
    End Function

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!