Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
... proprio nessuna soluzione?
Tutti i collegamenti sarebbero da rifare a mano?
Ciao Reggio,
Credo proprio di no!
Visto che stai utilizzando Excel2007, il quale non offre l'evento Workbook_AfterSave, 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
'--------->>
Public Sub myAftersave(sNewName As String, _
sName As String, _
sCurrName As String, _
sShortname)
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim sFilename As String
On Error GoTo XIT
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set WB = Workbooks.Open(sName)
If Not WB Is Nothing Then
With WB
For Each SH In .Worksheets
SH.UsedRange.Replace What:=sCurrName, _
Replacement:=sShortname
Next SH
.SaveAs Filename:=sNewName, _
FileFormat:=WB.FileFormat
.Close Savechanges:=False
End With
End If
XIT:
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
'<<=========
Ctrl-R per entrare nella finestra del Project Explorer
Fai doppio clic su ThisWorkbook e incolla il seguente codice di evento:
'=========>>
Option Explicit
'--------->>
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Res As Variant
Dim sShortname As String
Dim sNewName As String, sNewName2 As String
Dim sOldName As String, sOldName2 As String
Dim sStr As String
Dim destWB As Workbook
Const aStr As String = "Compilami" '\ Nome originale (senza estensione)
Const bStr As String = "Grafico" '\ Nome originale (senza estensione)
sShortname = Me.Name
sOldName = Me.FullName
sOldName2 = Replace(sOldName, aStr, bStr)
On Error GoTo XIT
Application.EnableEvents = False
If SaveAsUI = True Then
Cancel = True
Res = Application.GetSaveAsFilename(Me.Name, filefilter:= _
"Excel 97-2003 (*.xls),*.xls,Excel 2007 Macro (*.xlsm)," & _
"*.xlsm,Excel 2007 No Macro (*.xlsx),*.xlsx")
If Res <> False Then
sNewName = Res
Me.SaveAs Filename:=Res
sNewName2 = Replace(Res, aStr, bStr)
sNewName2 = Replace(sNewName2, "xls", "xlsx")
End If
Else
Me.Save
End If
If Me.Name <> sShortname Then
Call myAftersave(sNewName2, sOldName2, sShortname, Me.Name)
End If
XIT:
Application.EnableEvents = True
End Sub
'<<========
Alt-Q per chiudere l'editor di VBA e tornare a Excel.
Salva il file con un estensione xlsm.
Ora, ogni volta che il file Compilami,xlsm viene salvato con un nome diverso, il corrispondente file Grafico.xlsx verrà aperto automaticamente in modo nascosto; tutti i link verranno rinominati in accordo con il nuovo nome per il file Compilami. Infine, il file Grafico verrà salvato e chiuso con i collegamenti aggiornati.
L'unica operazione manuale è di accettare l'aggiornamento dei collegamenti e posso rimuovere quel singolo clic, se vuoi.
A proposito, l'evento Workbook_AfterSave è venuto con Excel 2010.
Postscriptum: nella procedura Workbook_BeforeSave, ho sostituito ActiveWorkbook con Me
===
Regards,
Norman