Di seguito viene riportata l'interfaccia grafica che è
stata realizzata al fine di agevolare l'utente nell'utilizzo del programma.

Esempio di risultato ottenuto (i dati sono stati opportunamente modificati, al fine di garantire la riservatezza dell'azienda):
Tabelle accedute, tipo e numero di accessi:
| Nome Tabella |
|
|
|
|
| Ordacq01 |
|
|
|
|
| System07 |
|
|
|
|
| System08 |
|
|
|
|
| Gestven03 |
|
|
|
|
| Datibase02 |
|
|
|
|
| Config10 |
|
|
|
|
Campi delle tabelle accedute, tipo e numero di accessi:
| Tabella / Campo |
|
|
|
|
|
|
|
| Ordacq01.NumOrd |
|
|
|
|
|
|
|
| Ordacq01.Quantità |
|
|
|
|
|
|
|
| Ordacq01.Data |
|
|
|
|
|
|
|
| Datibase02.Stile |
|
|
|
|
|
|
|
| Config10.NomeUtente |
|
|
|
|
|
|
|
| Config10.Diritti |
|
|
|
|
|
|
|
Qui di seguito si può trovare il codice che si
occupa di preparare il documento per l'analisi e che analizza le SELECT,
le istruzioni SQL più complicate, a causa dell'elevato numero di
casistiche possibili.
Public Sub AnalizzaProgramma(ByVal NomeProg, ByVal ChiediCreaRecord,
ByVal ChiediRimpiazza, ByRef NP, ByRef NT, ByRef NR)
'
' AnalizzaProgramma Macro
' Macro registrata il 04/10/99 da Paolo Spangher
'
' ***************************************************************
' Variabili di base per il DATABASE ACCESS
DBName = "F:\galileo\doc\docgest\GALILEO_NOSTRA_PROPOSTA.mdb"
' Nome del database da utilizzare
AnaPro = "ANAGRAFICA_PROGRAMMI" ' Nome della tabella di anagrafica
dei programmi
AnaTab = "ANAGRAFICA_TABELLE" ' Nome della tabella di anagrafica
tabelle
RelProTab = "REL_PROGRAMMA_TABELLE" ' Nome della tabella che
contiene le relazioni tra programmi e tabelle (i risultati di questa macro!)
RelProTabCam = "REL_PROGRAMMI_TABELLE_CAMPI" ' Nome della tabella
che contiene le relazioni tra programmi e tabelle (i risultati di questa
macro!)
' ***************************************************************
' Preparazione del file per l'analisi
' NomeProg = ActiveDocument.Name ' catturo
il nome del documento
If InStr(1, NomeProg, ".", vbTextCompare)
<> 0 Then
NomeProg = Left(NomeProg,
InStr(1, NomeProg, ".", vbTextCompare) - 1)
End If
' Inserire = False
Ris = VerificaProgramma(NomeProg, ChiediCreaRecord,
ChiediRimpiazza) ' Verifica che esista il codice del programma
If Ris = vbCancel Then
ActiveDocument.Close
(wdDoNotSaveChanges)
Exit Sub
End If
Selection.WholeStory ' Seleziono tutto
Selection.Copy
ActiveDocument.Close (wdDoNotSaveChanges)
' Chiudo il documento originale per evitare danni!
Documents.Add 'Creo il documento copia dell'originale
Selection.Paste
DocIni = ActiveDocument.Name ' Catturo il
nome del documento iniziale
' Pulizia dei commenti per non sballare i conteggi (SQL nei commenti)
Richieste.Azione.Caption = "Cancellazione
dei commenti..."
Richieste.Bar1.Value = 10
Richieste.Repaint
Windows(DocIni).Activate 'mi riposiziono
sul file da analizzare
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
'Selection.Text = "Pippo"
' Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "/\*(*)\*/"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Conversione delle tabulazioni in spazio per evitare problemi
Richieste.Azione.Caption = "Conversione dei
segni di tabulazione in spazi..."
Richieste.Repaint
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text
= " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Sostituzione delle union con ;
Richieste.Azione.Caption = "Sostituzione
delle UNION..."
Richieste.Repaint
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "<union>"
.Replacement.Text
= ";"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce select "spazio" con select "a capo"
Richieste.Azione.Caption = "Formattazione
delle SELECT..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "select "
.Replacement.Text
= "select^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce "spazio" from con "a capo" from
Richieste.Azione.Caption = "Formattazione
delle FROM..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " from"
.Replacement.Text
= "^p from"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce where "spazio" con where "a capo"
Richieste.Azione.Caption = "Formattazione
delle WHERE..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "where "
.Replacement.Text
= "where^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce "spazio" where con "a capo" where
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " where"
.Replacement.Text
= "^pwhere"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce update "spazio" con update "a capo"
Richieste.Azione.Caption = "Formattazione
delle UPDATE..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "update "
.Replacement.Text
= "update^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce "spazio" set con "a capo" set
Richieste.Azione.Caption = "Formattazione
delle SET..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " set"
.Replacement.Text
= "^p set"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sostituisce insert into "spazio" con insert into "a capo"
Richieste.Azione.Caption = "Formattazione
delle INTO..."
Richieste.Repaint
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "insert into
"
.Replacement.Text
= "insert into^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Mette = nella forma più consona
Richieste.Azione.Caption = "Formattazione
dei segni..."
Richieste.Repaint
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(?)="
.Replacement.Text
= "\1 = "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' *****************************************************************************
' *****************************************************************************
' **************************** CICLO PER LE SELECT ****************************
' *****************************************************************************
' *****************************************************************************
Richieste.Azione.Caption = "Analisi delle
tabelle delle SELECT..."
Richieste.Bar1.Value = 15
Richieste.Repaint
Documents.Add 'Creo il documento di destinazione
dei dati
DocTem = ActiveDocument.Name ' setto il numero
della finestra
Windows(DocIni).Activate 'mi riposiziono sul file da analizzare
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti i comandi
di FROM dalle SELECT (con WHERE)
' I risultati vengono
messi in un nuovo documento
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[!""_]<select>[!"";]@<from>[!""]@;" ' No _ per evitare il
BUG di Word
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.Copy
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
Windows(DocIni).Activate 'mi riposiziono sul file da analizzare
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
Documents.Add
DocTe1 = ActiveDocument.Name ' setto il numero
della finestra
Windows(DocTem).Activate 'mi posiziono
sul file temporaneo
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti i comandi
di FROM dalle SELECT (con WHERE)
' I risultati vengono
messi in un nuovo documento
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<from>[!%;]@<where>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.Copy
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
' *******************************************
' ** Parte per la sostituzione degli alias **
' *******************************************
' Seleziona il testo appena copiato
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<from>[!%;]@<where>"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Toglie dalla selezione from e where
Selection.MoveStart unit:=wdLine, Count:=1
Selection.MoveEnd unit:=wdLine, Count:=-1
If InStr(1, Selection.Text, ",", vbTextCompare) = 0 Then
Speciale = True
Else
Speciale = False
End If
' Seleziona una riga e la passa alla funzione che trova gli alias
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
' Espando la selezione fino alla select
While InStr(1, Selection.Text, "select", vbTextCompare) = 0
Selection.MoveUp unit:=wdLine, Count:=1, Extend:=wdExtend
Wend
Selection.HomeKey
' Seleziona tutta la select che contiene l'alias
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<select>[!"";]@;"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
While InStr(1, Selection.Text, "where", vbTextCompare) = 0
TornaAlias Selection.Text, Tabella, Alias
If Tabella <> Alias Then ' Sostituisce l'alias
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Alias
.Replacement.Text = Tabella
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo 1
End If
If Speciale Then
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[!.:](<t_??????>)"
.Replacement.Text = " " & Tabella & "\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo 1
End If
' Procede con la riga successiva
Selection.MoveDown
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Wend
Selection.EndKey unit:=wdStory ' Vado alla fine del file, per gli inserimenti
successivi
' *******************************************
Windows(DocTem).Activate 'mi riposiziono sul file da analizzare
Selection.EndKey ' Vado alla fine del file, per gli inserimenti successivi
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti
i comandi di FROM dalle SELECT (senza WHERE)
' I risultati vengono
messi nel documento temporaneo
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<from>[!<where>]@;"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.Copy
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
Selection.TypeText Text:="where" 'aggiunge la scritta where per successive
analisi
' *******************************************
' ** Parte per la sostituzione degli alias **
' *******************************************
' Seleziona il testo appena copiato
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<from>[!%;]@<where>"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Toglie dalla selezione from e where
Selection.MoveStart unit:=wdLine, Count:=1
Selection.MoveEnd unit:=wdLine, Count:=-1
If InStr(1, Selection.Text, ",", vbTextCompare) = 0 Then
Speciale = True
Else
Speciale = False
End If
' Seleziona una riga e la passa alla funzione che trova gli alias
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
' Espando la selezione fino alla select
While InStr(1, Selection.Text, "select", vbTextCompare) = 0
Selection.MoveUp unit:=wdLine, Count:=1, Extend:=wdExtend
Wend
Selection.HomeKey
' Seleziona tutta la select che contiene l'alias
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<select>[!"";]@;"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
While InStr(1, Selection.Text, "where", vbTextCompare) = 0
TornaAlias Selection.Text, Tabella, Alias
If Tabella <> Alias Then ' Sostituisce l'alias
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Alias
.Replacement.Text = Tabella
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo 1
End If
If Speciale Then
Windows(DocTem).Activate 'mi posiziono sul file temporaneo
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[!.:](<t_??????>)"
.Replacement.Text = " " & Tabella & "\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo 1
End If
' Procede con la riga successiva
Selection.MoveDown
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Wend
Selection.EndKey unit:=wdStory ' Vado alla fine del file, per gli inserimenti
successivi
' *******************************************
Windows(DocTem).Activate 'mi riposiziono sul file da analizzare
Selection.EndKey ' Vado alla fine del file, per gli inserimenti successivi
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
' Windows(DocTem).Activate 'mi posiziono
sul file temporaneo
' ActiveDocument.Close (wdDoNotSaveChanges)
' Il documento temporaneo secondario non serve più,
' DocTem = DocTe1 'DocTem diventa = a DocTe1!
Windows(DocTe1).Activate 'mi posiziono
sul file temporaneo
' Elimino le eventuali virgole dopo le tabelle
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ","
.Replacement.Text
= "^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Elimino gli eventuali punti e virgola dopo
le tabelle
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ";"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
TogliTabelleExtra ' Elimino tabelle agggiuntive,
per fare JOIN (es. xxx xxx_1)
' Elimino le tabelle duplicate all'interno
di una select
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do
Selection.HomeKey
unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<from>*<where>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.MoveStart unit:=wdLine, Count:=1
Selection.MoveEnd unit:=wdLine, Count:=-1
If Selection.Paragraphs.Count > 1 Then ' Se ho trovato + di una riga
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragrafi", _
SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending,
_
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:=
_
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:=
_
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID
_
:=wdLanguageNone
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
nometab = Selection.Text
Selection.MoveDown unit:=wdLine, Count:=1
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
While InStr(1, Selection.Text, "where", vbTextCompare) = 0
If nometab = Selection.Text Then
Selection.Cut
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Else
nometab = Selection.Text
Selection.MoveDown unit:=wdLine
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
End If
Wend
End If
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
' Elimino tutte le from
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "from"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Elimino tutte le where
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "where^p"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
False
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Tolgo eventuali spazi lasciati dalle from,
where
TogliTabelleExtra ' Elimino tabelle agggiuntive,
per fare JOIN (es. xxx xxx_1)
' Converto il testo (lista di tabelle ingres)
in tabella Word
Selection.WholeStory
If ActiveDocument.ComputeStatistics(wdStatisticCharacters)
> 1 Then ' Se ho trovato qualcosa
Selection.ConvertToTable
Separator:=wdSeparateByParagraphs, NumColumns:=1, _
Format:=wdTableFormatNone, ApplyBorders:=True, ApplyShading _
:=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True, _
ApplyLastRow:=False, ApplyFirstColumn:=True, ApplyLastColumn:=False, _
AutoFit:=False
' Inserisco
una riga vuota all'inizio della tabella per ovviare al bug di word dell'ordinamento
Selection.InsertRows
1
ActiveDocument.Tables(1).Select
Selection.Range.Case
= wdLowerCase
If ActiveDocument.Tables(1).Rows.Count
> 2 Then
Selection.SortAscending ' Ordino la tabella
End If
' Crea l'intestazione
della seconda tabella, che conterrà i risultati
ActiveDocument.Tables(1).Rows(1).Select
Selection.Cut
Selection.GoTo What:=wdGoToLine,
Which:=wdGoToAbsolute, Count:=ActiveDocument.ComputeStatistics(wdStatisticLines)
+ 1
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Paste
ActiveDocument.Tables(2).Select
Selection.Delete
unit:=wdCharacter, Count:=1
ActiveDocument.Tables(2).Select
Selection.Cells.SetWidth
ColumnWidth:=CentimetersToPoints(5), RulerStyle:=wdAdjustNone
ActiveDocument.Tables(2).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(2).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(2).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(2).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(2).Select
Selection.Cells.AutoFit
' ridimensiona le colonne affinchè stiano in una pagina
' Compilazione della
prima riga della tabella
ActiveDocument.Tables(2).Cell(1,
1).Range.InsertAfter ("Nome Tabella")
ActiveDocument.Tables(2).Cell(1,
2).Range.InsertAfter ("SELECT")
ActiveDocument.Tables(2).Cell(1,
3).Range.InsertAfter ("UPDATE")
ActiveDocument.Tables(2).Cell(1,
4).Range.InsertAfter ("INSERT")
ActiveDocument.Tables(2).Cell(1,
5).Range.InsertAfter ("DELETE")
' Formattazione dello
stile della tabella (tutto centrato tranne la prima colonna)
ActiveDocument.Tables(2).Select
Selection.ParagraphFormat.Alignment
= wdAlignParagraphCenter
Selection.Font.Size
= 12
Selection.Font.Bold
= wdToggle
Selection.Font.Name
= "Arial"
ActiveDocument.Tables(2).Columns(1).Select
Selection.ParagraphFormat.Alignment
= wdAlignParagraphLeft
' Riempimento della
tabella dei risultati in base alle tabelle INGRES trovate
For i = 1 To ActiveDocument.Tables(1).Rows.Count
Tabe = ActiveDocument.Tables(1).Cell(i, 1).Range.Text 'Scelgo la tabella
di INGRES da analizzare
Tabe = Left(Tabe, Len(Tabe) - 2) ' Toglie un carattere strano alla fine
della stringa! (bug Word??)
ActiveDocument.Tables(2).Select ' Seleziona la tabella dei risultati
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<" & Tabe & ">"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then 'Indica se è stato trovato il testo
Riga = Selection.Cells(1).RowIndex
Num = Val(ActiveDocument.Tables(2).Cell(Riga, 2).Range.Text) ' Colonna
2 perchè aggiorno le SELECT
Num = Num + 1
ActiveDocument.Tables(2).Cell(Riga, 2).Range.Text = Num
Else ' crea una nuova riga nella tabella
'
Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=ActiveDocument.ComputeStatistics(wdStatisticLines)
+ 1
Selection.EndKey unit:=wdStory
Selection.InsertRows 1
Riga = ActiveDocument.Tables(2).Rows.Count
ActiveDocument.Tables(2).Cell(Riga, 1).Range.Text = Tabe
ActiveDocument.Tables(2).Cell(Riga, 2).Range.Text = "1"
ActiveDocument.Tables(2).Cell(Riga, 3).Range.Text = "0"
ActiveDocument.Tables(2).Cell(Riga, 4).Range.Text = "0"
ActiveDocument.Tables(2).Cell(Riga, 5).Range.Text = "0"
End If
Next i
ActiveDocument.Tables(1).Select
Selection.Cut ' Cancello
la tabella delle tabelle INGRES
DocRis = ActiveDocument.Name
' Salvo il numero della finestra dei risultati
Else '**********************************************************************************
Selection.GoTo What:=wdGoToLine,
Which:=wdGoToAbsolute, Count:=ActiveDocument.ComputeStatistics(wdStatisticLines)
+ 1
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
ActiveDocument.Tables.Add
Range:=Selection.Range, NumRows:=1, NumColumns:=1
ActiveDocument.Tables(1).Rows(1).Select
ActiveDocument.Tables(1).Select
Selection.Delete
unit:=wdCharacter, Count:=1
ActiveDocument.Tables(1).Select
Selection.Cells.SetWidth
ColumnWidth:=CentimetersToPoints(5), RulerStyle:=wdAdjustNone
ActiveDocument.Tables(1).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(1).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(1).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(1).Columns.Add
'aggiunge una colonna
ActiveDocument.Tables(1).Select
Selection.Cells.AutoFit
' ridimensiona le colonne affinchè stiano in una pagina
' Compilazione della
prima riga della tabella
ActiveDocument.Tables(1).Cell(1,
1).Range.InsertAfter ("Nome Tabella")
ActiveDocument.Tables(1).Cell(1,
2).Range.InsertAfter ("SELECT")
ActiveDocument.Tables(1).Cell(1,
3).Range.InsertAfter ("UPDATE")
ActiveDocument.Tables(1).Cell(1,
4).Range.InsertAfter ("INSERT")
ActiveDocument.Tables(1).Cell(1,
5).Range.InsertAfter ("DELETE")
' Formattazione dello
stile della tabella (tutto centrato tranne la prima colonna)
ActiveDocument.Tables(1).Select
Selection.ParagraphFormat.Alignment
= wdAlignParagraphCenter
Selection.Font.Size
= 12
Selection.Font.Bold
= wdToggle
Selection.Font.Name
= "Arial"
ActiveDocument.Tables(1).Columns(1).Select
Selection.ParagraphFormat.Alignment
= wdAlignParagraphLeft
DocRis = ActiveDocument.Name
' Salvo il numero della finestra dei risultati
End If
' *****************************************
' *********** Ciclo per i campi ***********
' *****************************************
Richieste.Azione.Caption = "Analisi dei campi
delle SELECT..."
Richieste.Bar1.Value = 25
Richieste.Repaint
Documents.Add
DocTe1 = ActiveDocument.Name ' setto il numero
della finestra
Windows(DocTem).Activate 'mi posiziono
sul file temporaneo
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti i comandi
di FROM dalle SELECT (con WHERE)
' I risultati vengono
messi in un nuovo documento
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<select>[!%;]@<into>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.Copy
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
Windows(DocTem).Activate 'mi riposiziono sul file da analizzare
Selection.EndKey ' Vado alla fine del file, per gli inserimenti successivi
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti
i comandi di FROM dalle SELECT (senza WHERE)
' I risultati vengono
messi nel documento temporaneo
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<select>[!;]@<from>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
If InStr(1, Selection.Text, "into", vbTextCompare) = 0 Then ' prende le
selezioni senza into
Selection.Copy
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
Windows(DocTem).Activate 'mi riposiziono sul file da analizzare
End If
Selection.EndKey ' Vado alla fine del file, per gli inserimenti successivi
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
' Windows(DocTem).Activate
' ActiveDocument.Close (wdDoNotSaveChanges)
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Documents.Add
DocRis1 = ActiveDocument.Name ' Salvo il
numero della finestra dei risultati
' Crea l'intestazione della seconda tabella,
che conterrà i risultati
ActiveDocument.Tables.Add Range:=Selection.Range,
NumRows:=1, NumColumns:=8
' Compilazione della prima riga della tabella
ActiveDocument.Tables(1).Cell(1, 1).Range.InsertAfter
("Tab.Campo")
ActiveDocument.Tables(1).Cell(1, 2).Range.InsertAfter
("SEL")
ActiveDocument.Tables(1).Cell(1, 3).Range.InsertAfter
("UPD")
ActiveDocument.Tables(1).Cell(1, 4).Range.InsertAfter
("INS")
ActiveDocument.Tables(1).Cell(1, 5).Range.InsertAfter
("WSEL") ' Il campo appare nella where della select
ActiveDocument.Tables(1).Cell(1, 6).Range.InsertAfter
("WUPD") ' Il campo appare nella where della update
ActiveDocument.Tables(1).Cell(1, 7).Range.InsertAfter
("WINS") ' Il campo appare nella where della insert
ActiveDocument.Tables(1).Cell(1, 8).Range.InsertAfter
("WDEL") ' Il campo appare nella where della delete
' Formattazione dello stile della tabella
(tutto centrato tranne la prima colonna)
ActiveDocument.Tables(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 12
Selection.Font.Bold = wdToggle
Selection.Font.Name = "Arial"
ActiveDocument.Tables(1).Columns(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Windows(DocTe1).Activate
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ":????????"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do
Windows(DocTe1).Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<????????>.<????????>" ' Le tabelle e i campi DEVONO ESSERE
DI 8 CARATTERI!
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then
Tabe = Selection.Text
Windows(DocRis1).Activate ' Vado nel documento dei risultati
ActiveDocument.Tables(1).Select ' Seleziona la tabella dei risultati
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<" & Tabe & ">"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then 'Indica se è stato trovato il testo
Riga = Selection.Cells(1).RowIndex
Num = Val(ActiveDocument.Tables(1).Cell(Riga, 2).Range.Text) ' Colonna
2 perchè aggiorno le SELECT
Num = Num + 1
ActiveDocument.Tables(1).Cell(Riga, 2).Range.Text = Num
Else ' crea una nuova riga nella tabella
'
Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=ActiveDocument.ComputeStatistics(wdStatisticLines)
+ 1
Selection.EndKey unit:=wdStory
Selection.InsertRows 1
Riga = ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables(1).Cell(Riga, 1).Range.Text = Tabe
ActiveDocument.Tables(1).Cell(Riga, 2).Range.Text = "1"
ActiveDocument.Tables(1).Cell(Riga, 3).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 4).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 5).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 6).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 7).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 8).Range.Text = "0"
End If
Else
Fine = True
End If
Loop Until Fine
Windows(DocTe1).Activate
ActiveDocument.Close (wdDoNotSaveChanges)
' ***********************************
' ** Parte per i campi nelle where **
' ***********************************
Documents.Add
DocTe1 = ActiveDocument.Name ' setto il numero
della finestra
Windows(DocTem).Activate 'mi posiziono
sul file temporaneo
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do ' Ciclo per trovare tutti i comandi
di FROM dalle SELECT (con WHERE)
' I risultati vengono
messi in un nuovo documento
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<where>[!%;]@;"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop quando si raggiunge la fine del documento
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then 'Indica se è stato trovato il testo
Selection.Copy
Windows(DocTe1).Activate 'mi posiziono sul file temporaneo
Selection.Paste
Selection.TypeParagraph
Windows(DocTem).Activate 'mi riposiziono sul file da analizzare
Selection.EndKey ' Vado alla fine del file, per gli inserimenti successivi
Else
Fine = True
End If
Loop Until Fine ' Loop finche non viene raggiunta
la fine del documento
Windows(DocTem).Activate
ActiveDocument.Close (wdDoNotSaveChanges)
Windows(DocTe1).Activate 'mi posiziono
sul file temporaneo
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ":????????"
.Replacement.Text
= ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord =
False
.MatchWildcards =
True
.MatchSoundsLike
= False
.MatchAllWordForms
= False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst,
Name:="" ' vado all'inizio del documento
Fine = False
Do
Windows(DocTe1).Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<????????>.<????????>" ' Le tabelle e i campi DEVONO ESSERE
DI 8 CARATTERI!
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found
Then
Tabe = Selection.Text
Windows(DocRis1).Activate ' Vado nel documento dei risultati
ActiveDocument.Tables(1).Select ' Seleziona la tabella dei risultati
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<" & Tabe & ">"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then 'Indica se è stato trovato il testo
Riga = Selection.Cells(1).RowIndex
Num = Val(ActiveDocument.Tables(1).Cell(Riga, 5).Range.Text) ' Colonna
5 perchè aggiorno le SELECT
Num = Num + 1
ActiveDocument.Tables(1).Cell(Riga, 5).Range.Text = Num
Else ' crea una nuova riga nella tabella
'
Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=ActiveDocument.ComputeStatistics(wdStatisticLines)
+ 1
Selection.EndKey unit:=wdStory
Selection.InsertRows 1
Riga = ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables(1).Cell(Riga, 1).Range.Text = Tabe
ActiveDocument.Tables(1).Cell(Riga, 2).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 3).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 4).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 5).Range.Text = "1"
ActiveDocument.Tables(1).Cell(Riga, 6).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 7).Range.Text = "0"
ActiveDocument.Tables(1).Cell(Riga, 8).Range.Text = "0"
End If
Else
Fine = True
End If
Loop Until Fine
Windows(DocTe1).Activate
ActiveDocument.Close (wdDoNotSaveChanges)