+ Reply to Thread
Results 1 to 13 of 13

Right-click on file and click element

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Right-click on file and click element

    Hello everyone
    I am searching for a way to select specific file (any type of files) and right-click it using VBA relying on API (I don't know exactly the best method) then select specific element from the popup menu ..example : Properties
    This is just an example
    Is there a way to do that or not?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    Are you only wanting to see file properties?

    If so, here is a different way to achieve that....
    - user form used
    - file dialog allows user to select a file
    - listing of properties dumped to ListBox and to sheet "Values"

    Test in attached file by clicking on button.

    UserForm code....
    Private Sub cb_ChooseFile_Click()
    Dim fName As String, Divider As Integer, FolderPath As String, FileName As String
        Application.ScreenUpdating = False
        With Application.FileDialog(msoFileDialogOpen)
                .AllowMultiSelect = False
                .Show
                On Error Resume Next
                fName = .SelectedItems(1)
                    Divider = InStrRev(fName, "\")
                    MyFolderPath = Left(fName, Divider - 1)
                    MyFileName = Mid(fName, Divider + 1, Len(fName) - Divider)
        
        End With
        
        Call GetValues(MyFolderPath, MyFileName)
        
        Application.ScreenUpdating = True
        Me.ListBox1.List = Sheets("Values").Range("A1").CurrentRegion.Offset(, 1).Resize(, 2).Value
    
    End Sub
    Private Sub GetValues(MyFolderPath, MyFileName)
    
    Dim cObj As Object, r As Integer, x As Integer, myValue As String, myDesc As String, ws As Worksheet
        Set ws = Sheets("Values"): ws.Range("A1:C288").ClearContents
        Set cObj = CreateObject("shell.application").Namespace(MyFolderPath)
        With cObj
            For x = 0 To 288
                On Error Resume Next
                myValue = .getdetailsof(.Items.Item(MyFileName), x)
                myDesc = .getdetailsof(vbNull, x)
                     If x = 0 Then Me.Label1 = myValue
                    If myValue <> "" Then
                        r = r + 1
                        With ws
                            .Cells(r, 1).Value = x
                            .Cells(r, 2).Value = myDesc
                            .Cells(r, 3).Value = myValue
                        End With
                    End If
            Next
        End With
    
    End Sub
    YasserKhalil v1 File Properties.xlsm
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    Thank you very much for your solution ... I liked it a lot
    But the objective of that is not to select a file by filedialog and Properties is just example
    If you have a look at this thread you will get my target
    https://www.excelforum.com/excel-pro...-the-link.html

    I will have a list of files from specific path in column A and I would like to Copy DropBox Link from right-click menu and then paste the copied link to column B
    That's my target .. I think it can be done using API but I have no idea about it
    Thanks a lot

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    Please test something for me
    - I do not use Dropbox, but I do use OneDrive which is similar

    I TESTED LIKE THIS ON MY LAPTOP - IT WORKED WITH ONEDRIVE
    An example with OneDrive file (using the file I attached to post#2)
    - its name is attribute 0 : YasserKhalil v1 File Properties.xlsm
    - its Folder Path is attribute 186 : C:\Users\kev\OneDrive\Documents
    - its Path is attribute 189 : C:\Users\kev\OneDrive\Documents\YasserKhalil v1 File Properties.xlsm
    I created a link with C:\Users\kev\OneDrive\Documents\YasserKhalil v1 File Properties.xlsm, the correct file is opened


    Run the macro that I provided in post#2 against one of your files that are on Dropbox
    - I think the Path attribute may provide a usable link path
    - that is how your computer finds the file
    - use that value and create a link and test it
    - if it works I will modify the VBA for you
    - did the link work?
    Last edited by kev_; 12-09-2017 at 03:12 PM.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    Thanks a lot .. I don't know if I applied the steps correctly or not
    I have put the file 'YasserKhalil v1 File Properties' in dropbox folder in a sub folder named "XYZ" and then opened the excel file 'YasserKhalil v1 File Properties' and from the userform I selected the same file 'YasserKhalil v1 File Properties' and I got the following snapshot (Link unresolved)
    Help.png

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    Your Path value (2 lines above Link Status) looks very similar to what I would expect
    It looks as though it could work
    I will post modified VBA for you to test tomorrow.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    Thanks a lot. I will be waiting for you
    Thank you very much

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    This works for me with OneDrive
    The "link" is created to the local folder and it opens the file on OneDrive
    I added folder Delete to OneDrive for testing. So my path is :
    C:\Users\kev\OneDrive\Documents\Delete\WordToExcelTextBoxV3.xlsm

    Test in attached file by putting
    - file name including extension in column A
    - dropbox main path in column F - perhaps: C:\Users\Future\dropbox
    - sub folder in column G - perhaps: XYZ
    - run macro with {CTRL} k

    (like in picture)

    WhatIGet.jpg

    Sub FindFile()
        Dim ws As Worksheet, cel As Range, rng As Range, PathToFile As String
        Set ws = Sheets("FileList")
        Set rng = ws.Range("A2", ws.Range("A" & Rows.Count).End(xlUp))
            For Each cel In rng
                With cel.Offset(, 1)
                    PathToFile = .Offset(, 4) & "\" & .Offset(, 5) & "\" & cel.Value
                    Debug.Print PathToFile
                    Dir (PathToFile)
                        Select Case Dir(PathToFile) <> vbNullString
                                Case True:  ws.Hyperlinks.Add cel.Offset(, 1), PathToFile
                                Case False: .Value = "Not Found"
                        End Select
                End With
            Next cel
    End Sub
    Attached Files Attached Files
    Last edited by kev_; 12-10-2017 at 05:18 AM.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    That's great Kev. Thank you very much
    In fact this approach is very very good but the result is not a hyperlink to the files. I admit this solution is very well. I just need a link of the file on DropBox itself
    If I right-click the file in XYZ folder and click "Copy Dropbox link" I got something like that
    https://www.dropbox.com/s/txqf5cnhr72jk6w/Penguins.jpg?dl=0
    This is the link I was after to grab in column B

    Best and Kind Regards

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    OK - so you want to do more that just hyperlink to each file

    I have a simple solution but it will only work with Excel files
    - Are the files listed in column A all Excel files?

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    Yes you are right
    As for the files are listed in Column A as you attached .. but they are not just excel files. These files are of different types
    Why will it work for excel files only? ..

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Right-click on file and click element

    Having the local link means
    - VBA can open an Excel file
    - ActiveWorkbook.FullName returns the actual path
    - close the file again

    BUT back to the drawing board...
    ... need to find a different way..

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Right-click on file and click element

    Thank you very much Kev for your interest in this issue
    I appreciate that a lot. Regards

+ 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. Get element by value? [click on option button on web page]
    By emjay973 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2017, 05:52 PM
  2. [SOLVED] make button single click to avoid user double click
    By Muzza1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2016, 01:02 AM
  3. Macro to click a 'choose file' button on webpage, browse for a local file, and click open
    By Insaintime32 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-06-2016, 04:46 PM
  4. [SOLVED] ActiveX combobox click triggers unwanted another comboxbox click event
    By aprildu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-12-2015, 10:08 AM
  5. Replies: 0
    Last Post: 03-06-2013, 12:52 PM
  6. Double click on element in dynamically defined chart
    By padleywoods in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-07-2012, 01:54 PM
  7. Replies: 4
    Last Post: 08-02-2005, 09:05 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