Condividi tramite

Link in tabella in query di excel

Anonimo
2018-07-26T09:43:23+00:00

ciao a tutti.

ho creato una query su excel per fare una lista di file presenti in una cartella. Ho questa vista:

Vorrei, nella colonna "Name", avere il link cliccabile per aprire direttamente il file.

è possibile fare una cosa del genere?

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

1 risposta

Ordina per: Più utili
  1. Anonimo
    2018-07-27T07:48:36+00:00

    Ciao gtsolid,

    ho creato una query su excel per fare una lista di file presenti in una cartella. Ho questa vista:

    Vorrei, nella colonna "Name", avere il link cliccabile per aprire direttamente il file.

    è possibile fare una cosa del genere?

    Prova qualcosa del genere:

    • Alt+F11 per aprire l'editor di VBA
    • Alt+IM per inserire un nuovo modulo di codice
    • Nel nuovo modulo vuoto, incolla il seguente codice:

    '=========>>

    Option Explicit

    Option Compare Text

    '--------->>

    Public Sub Elenca_File_Con_Collegamenti_Ipertestuali()

        Dim WB As Workbook

        Dim SH As Worksheet

        Dim oFSO As Object

        Dim oShell As Object

        Dim oFile As Object

        Dim oFiles As Object

        Dim destRng As Range

        Dim sPath As String

        Dim bFlag As Boolean

        Dim Res As VbMsgBoxResult

        Dim iCtr As Long

        Const sFoglioElenco As String = "ElencoFile"

        Application.ScreenUpdating = False

        Set oFSO = CreateObject("Scripting.FileSystemObject")

        Do

            bFlag = False

            Set oShell = CreateObject("Shell.Application"). _

                         Browseforfolder(0, "SCEGLIE DIRECTORY", 0, "C:\")

            On Error Resume Next

            sPath = oShell.self.Path

            Set oFiles = oFSO.GetFolder(sPath).Files

            If Err.Number <> 0 Then

                Res = MsgBox( _

                      Prompt:="Non hai precisato una directory valida!" _

                              & vbNewLine & _

                              "Vuoi riprovare?", _

                      Buttons:=vbYesNoCancel, _

                      Title:="Seleziona Folder")

                If Res <> vbYes Then Exit Sub

                bFlag = True

            End If

            On Error GoTo 0

        Loop Until bFlag = False

        Set WB = ThisWorkbook

        With WB

            If SheetExists(sFoglioElenco) Then

                Set SH = .Sheets(sFoglioElenco)

                SH.UsedRange.ClearContents

            Else

                Set SH = .Sheets.Add(After:=.Sheets(.Sheets.Count))

                SH.Name = sFoglioElenco

           End If

        End With

        With SH

            With .Range("A1")

                .Value = "Elenco File:"

                .ColumnWidth = 45

                .Parent.Hyperlinks.Add _

                        Anchor:=.Offset(0, 1), _

                        Address:=sPath, _

                        TextToDisplay:=sPath

            End With

            With .Range("A2")

                With .Resize(1, 3)

                    .Value = Array("Nome File", _

                                   "Data Modificata", _

                                   "Peso File (Kb)")

                    .Resize(1, 3).Interior.Color = RGB(192, 192, 192)

                End With

                With .Offset(0, 1).Resize(1, 2)

                    .ColumnWidth = 15

                    .HorizontalAlignment = xlCenter

                End With

            End With

            For Each oFile In oFiles

                iCtr = iCtr + 1

                Set destRng = ActiveSheet.Range("A2").Offset(iCtr)

                .Hyperlinks.Add _

                        Anchor:=destRng, _

                        Address:=oFile.Path, _

                        TextToDisplay:=oFile.Name

                With destRng

                    .Offset(0, 1) = oFile.datelastModified

                    With .Offset(0, 2)

                        .Value = Round(oFile.Size / 1024, 1)

                        .NumberFormat = "#,##0.0"

                    End With

                End With

            Next oFile

        End With

    End Sub

    '--------->>

    Public Function SheetExists(sSheetName As String, _

                                Optional ByVal WB As Workbook) As Boolean

        On Error Resume Next

        If WB Is Nothing Then

            Set WB = ThisWorkbook

        End If

        SheetExists = CBool(Len(WB.Sheets(sSheetName).Name))

        On Error GoTo 0

    End Function

    '<<=========

    • Alt+Q per chiudere l'editor di VBA e tornare a Excel
    • Salva il file con l’estensione xlsm
    • Alt+F8 per aprire  la finestra di gestione delle macro
    • Seleziona Elenca_File_Con_Collegamenti_Ipertestuali
    • Esegui

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento