Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Maurizio,
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
Private Declare Function SHGetFolderPath _
Lib "shfolder.dll" _
Alias "SHGetFolderPathA" ( _
ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
ByVal hToken As Long, _
ByVal dwReserved As Long, _
ByVal lpszPath As String) As Long
Private Const CSIDL_PERSONAL As Long = &H5
Dim iCtr As Long
Dim rCell As Range
'--------->>
Public Sub SelezionaCartella()
Dim WB As Workbook
Dim destSH As Worksheet
Dim destRng As Range
Dim FD As FileDialog
Dim sFolder As String, sPercorso As String
Dim sMsg As String, sTitle As String
Dim iButtons As Long
Set FD = Application.FileDialog(msoFileDialogFolderPicker)
With FD
.InitialFileName = MyDocuments
.Title = "Seleziona Directory"
.ButtonName = "Seleziona"
If .Show = -1 Then
sFolder = .SelectedItems(1)
End If
End With
If sFolder = vbNullString Then
sMsg = "Non hai selezionato una Directory! (:-"
GoTo XIT
End If
On Error Resume Next
Set destRng = Application.InputBox( _
Prompt:="Seleziona la destinazione per " _
& "i collegamenti ipertestuali", _
Default:=ActiveCell.Address(0, 0, , 1), _
Title:="SELEZIONA FOGLIO & CELLA", _
Type:=8)
On Error GoTo 0
If Not destRng Is Nothing Then
With destRng
Set destSH = .Parent
Set rCell = .Cells(1)
End With
Set WB = destSH.Parent
With WB
.BuiltinDocumentProperties("Hyperlink base") = _
"\NoServer\NoFolder"
iCtr = 0
Call CreaHyperlink(sFolder, destRng.Cells(1))
End With
Else
sMsg = "Non hai selezionato una destinazione " _
& "per i collegamenti ipertestuali!" _
& vbNewLine & vbNewLine _
& "Riprova!"
GoTo XIT
End If
XIT:
With FD
.InitialFileName = ""
.Title = ""
.ButtonName = ""
End With
If sMsg <> vbNullString Then
sTitle = "OPERAZIONE ANNULLATA"
iButtons = vbCritical
Else
rCell.EntireColumn.AutoFit
sMsg = "Finita!" _
& vbNewLine & vbNewLine _
& iCtr & " collegamenti ipertestuali " _
& "sono stati creati nell'intervallo " _
& rCell.Resize(iCtr).Address(0, 0) _
& " sul foglio: " & destSH.Name & " del file " _
& WB.Name
sTitle = "REPORT"
iButtons = vbInformation
End If
Call MsgBox( _
Prompt:=sMsg, _
Buttons:=vbCritical, _
Title:="OPERAZIONE ANNULLATA")
End Sub
'--------->>
Public Sub CreaHyperlink(sPercorso As String, Rng As Range)
Dim oFSO As Object
Dim oFolder As Object
Dim oSubFolder As Object
Dim oFile As Object
Dim sFilename As String
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPercorso)
On Error Resume Next
For Each oSubFolder In oFolder.SubFolders
CreaHyperlink oSubFolder.Path, Rng
Next oSubFolder
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
For Each oFile In oFolder.Files
With oFile
sFilename = Split(.Name, ".")(0)
Rng.Value = sFilename
ActiveSheet.Hyperlinks.Add _
Anchor:=Rng, _
Address:=.Path
iCtr = iCtr + 1
End With
Set Rng = Rng.Offset(1)
Next oFile
XIT:
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
'--------->>
Public Function MyDocuments() As String
Dim pos As Long
Dim sBuffer As String
sBuffer = Space$(260)
If SHGetFolderPath(0&, CSIDL_PERSONAL, -1, 0&, sBuffer) = 0 Then
pos = InStr(1, sBuffer, Chr(0))
MyDocuments = Left$(sBuffer, pos - 1)
End If
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 la procedura: SelezionaCartella
- Esegui
===
Regards,
Norman