0% found this document useful (0 votes)
28 views3 pages

Excel VBA UI Module for File Analysis

The document is a VBA module that defines user interface functionalities for a Word and Excel integration tool. It includes procedures for analyzing files, resetting selections, and managing UI elements such as buttons for analysis, re-selection, and resetting. The module ensures proper initialization, error handling, and user feedback through message boxes.

Uploaded by

Majdi Belguith
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Excel VBA UI Module for File Analysis

The document is a VBA module that defines user interface functionalities for a Word and Excel integration tool. It includes procedures for analyzing files, resetting selections, and managing UI elements such as buttons for analysis, re-selection, and resetting. The module ensures proper initialization, error handling, and user feedback through message boxes.

Uploaded by

Majdi Belguith
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Attribute VB_Name = "Module_UI"

Option Explicit

' ==========================
' Bouton Analyze
' ==========================

Public Sub Analyze_Click()


' S�curiser l'initialisation
If gFileIndex Is Nothing Then Globals_Init

If gFileIndex Is Nothing Or [Link] = 0 Then


ShowNoFilesError
UI_ShowAnalyze True
Exit Sub
End If

' �tape 2 : Formatage Word


FormatWord_Step2

' �tape 3 : V�rification des labels


VerifyLabels_Step3

' �tape 4 : Extraction vers Excel


Extract_Step4

' Fermer Word � la fin du workflow


If Not gWdApp Is Nothing Then
[Link]
Set gWdApp = Nothing
End If

MsgBox "Analysis completed successfully!", vbInformation, "PROCESS DONE"


End Sub

' ==========================
' Bouton Select again
' ==========================
Public Sub Reselect_Click()
SelectFiles_Step1
End Sub

' ==========================
' Bouton RESET
' ==========================
Public Sub Reset_All()
Dim wsDetect As Worksheet, wsCert As Worksheet
Dim lastRow As Long

Set wsDetect = [Link](SHEET_DETECT)


Set wsCert = [Link](SHEET_CERT)

[Link]("B" & ROW_ERR1 & ":B" & ROW_ERR2).ClearContents


[Link]("B" & ROW_COUNT).ClearContents

lastRow = [Link]([Link], "B").End(xlUp).Row


If lastRow >= ROW_FILES_START Then
[Link]("B" & ROW_FILES_START & ":B" & lastRow).ClearContents
End If

ResetSelectionCompletely wsDetect
[Link]

UI_HideAnalyze
MsgBox "All selections, messages, and certificate data have been reset.",
vbInformation, "RESET COMPLETE"
End Sub

' ==========================
' Utilitaires UI
' ==========================
Public Sub UI_SetNote(ByVal msg As String, ByVal title As String)
With [Link](SHEET_DETECT)
.Range("B" & ROW_ERR1).value = msg
.Range("B" & ROW_ERR2).value = title
End With
End Sub

' Afficher/Masquer le bouton NEXT (si conserv�)


Public Sub UI_ShowNext(Optional ByVal show As Boolean = True)
Dim btn As Shape
On Error Resume Next
Set btn = [Link](SHEET_DETECT).Shapes("btnNext")
On Error GoTo 0
If Not btn Is Nothing Then
[Link] = IIf(show, msoTrue, msoFalse)
End If
End Sub

Public Sub UI_HideNext()


UI_ShowNext False
End Sub

' Afficher/Masquer le bouton ANALYZE


Public Sub UI_ShowAnalyze(Optional ByVal show As Boolean = True)
Dim btn As Shape
On Error Resume Next
Set btn = [Link](SHEET_DETECT).Shapes("btnAnalyze") ' V�rifie le
nom exact du bouton
On Error GoTo 0
If Not btn Is Nothing Then
[Link] = IIf(show, msoTrue, msoFalse)
End If
End Sub

Public Sub UI_HideAnalyze()


UI_ShowAnalyze False
End Sub

Private Sub ShowNoFilesError()


With [Link](SHEET_DETECT)
.Range("B" & ROW_ERR1 & ":B" & ROW_ERR2).ClearContents
.Range("B" & ROW_ERR1).value = "Error: No source file(s) selected."
.Range("B" & ROW_ERR2).value = "Please click 'Select Word files' and choose
at least one document."
End With
End Sub
' ===== Module_UI =====
Public Sub UI_CreateButtons()
Dim ws As Worksheet: Set ws = [Link](SHEET_DETECT)
' Analyze
EnsureButton ws, "btnAnalyze", "Analyze", "Analyze_Click", 120, 30, 20, 20
' Select again (Reselect)
EnsureButton ws, "btnReselect", "Select again", "Reselect_Click", 120, 30, 150,
20
' Reset
EnsureButton ws, "btnReset", "RESET", "Reset_All", 90, 30, 280, 20
' Next (si encore utilis�)
EnsureButton ws, "btnNext", "NEXT", "Next_Click", 90, 30, 380, 20
End Sub

Private Sub EnsureButton(ws As Worksheet, btnName As String, btnText As String,


macroName As String, _
width As Single, height As Single, left As Single, top As
Single)
Dim shp As Shape
On Error Resume Next
Set shp = [Link](btnName)
On Error GoTo 0
If shp Is Nothing Then
Set shp = [Link](msoShapeRoundedRectangle, left, top, width,
height)
[Link] = btnName
With shp
.[Link] = RGB(0, 112, 192)
.[Link] = msoFalse
.onAction = macroName
' Texte: TextFrame2 si dispo, sinon fallback TextFrame
On Error Resume Next
.[Link] = btnText
If [Link] <> 0 Then
[Link]
.[Link] = btnText
End If
On Error GoTo 0
End With
Else
[Link] = msoTrue
[Link] = macroName
End If
End Sub

You might also like