Hello everybody. I don't post much here, and am hoping somebody doesn't mind helping, because my VBA skills are not excellent.
I acquired a workbook, and have worked through most of the VBA setup. But I am stumped on a few remaining items and why they're set up this way.
Please bear with me, as I'm sure this is basic for most of you.
1) Code under "This Workbook":
I believe that this is to run "Initialize" macro. Not sure what the point of the application commandbars line is for.
Private Sub Workbook_Open() ----- Understand.
Application.CommandBars("Ply").Enabled = True ----- Do not understand.
Run "Initialize" ----- Understand, but uncertain why they separated "Initialize" into a module.
On Error Resume Next ----- Understand.
ActiveWorkbook.RefreshAll ----- Understand.
End Sub
2) Code under "Data" "Module" that is the Sub for the above:
This is the "Initialize" macro. I am not sure how it's connected to the "DataValidation", or what it's doing exactly. When I actually run the macro nothing seems to happen.
Dim X As New DataValidation ----- Understand.
Sub Initialize() ----- Understand.
Set X.qt = ThisWorkbook.Sheets("DATA").QueryTables(1) ----- Do not understand. I believe it's referencing the table in the below class module, but uncertain why it's separated into a class module.
End Sub
3) Code under "DataValidation" "ClassModule":
I understand that this is unprotecting a sheet, updating a table, and updating the Name manager. I'm not certain why it was created a "ClassModule" or if it's directly connected to "Initialize".
Public WithEvents qt As QueryTable ----- Do not understand.
Private Sub qt_BeforeRefresh(Cancel As Boolean) ----- Do not understand.
Worksheets("DATA").Unprotect Password:="-" ----- Understand.
End Sub
Private Sub qt_AfterRefresh(ByVal Success As Boolean) ----- Do not understand.
Worksheets("DATA").Unprotect Password:="-" ----- Understand.
Worksheets("DATA").Cells.Replace What:="-", Replacement:="", LookAt:=xlPart, MatchCase:=False ----- Understand.
Worksheets("DATA").Range("C5:C" & Worksheets("DATA").Range("C" & Rows.Count).End(xlUp).Row).Name = "CATEGORY" ----- Understand.
Worksheets("DATA").Columns("C:J").EntireColumn.AutoFit ----- Understand.
Worksheets("DATA").Protect Password:="-" ----- Understand.
Range("B1").Select ----- Understand.
End Sub
Thank you for your help and time.
I acquired a workbook, and have worked through most of the VBA setup. But I am stumped on a few remaining items and why they're set up this way.
Please bear with me, as I'm sure this is basic for most of you.
1) Code under "This Workbook":
I believe that this is to run "Initialize" macro. Not sure what the point of the application commandbars line is for.
Private Sub Workbook_Open() ----- Understand.
Application.CommandBars("Ply").Enabled = True ----- Do not understand.
Run "Initialize" ----- Understand, but uncertain why they separated "Initialize" into a module.
On Error Resume Next ----- Understand.
ActiveWorkbook.RefreshAll ----- Understand.
End Sub
2) Code under "Data" "Module" that is the Sub for the above:
This is the "Initialize" macro. I am not sure how it's connected to the "DataValidation", or what it's doing exactly. When I actually run the macro nothing seems to happen.
Dim X As New DataValidation ----- Understand.
Sub Initialize() ----- Understand.
Set X.qt = ThisWorkbook.Sheets("DATA").QueryTables(1) ----- Do not understand. I believe it's referencing the table in the below class module, but uncertain why it's separated into a class module.
End Sub
3) Code under "DataValidation" "ClassModule":
I understand that this is unprotecting a sheet, updating a table, and updating the Name manager. I'm not certain why it was created a "ClassModule" or if it's directly connected to "Initialize".
Public WithEvents qt As QueryTable ----- Do not understand.
Private Sub qt_BeforeRefresh(Cancel As Boolean) ----- Do not understand.
Worksheets("DATA").Unprotect Password:="-" ----- Understand.
End Sub
Private Sub qt_AfterRefresh(ByVal Success As Boolean) ----- Do not understand.
Worksheets("DATA").Unprotect Password:="-" ----- Understand.
Worksheets("DATA").Cells.Replace What:="-", Replacement:="", LookAt:=xlPart, MatchCase:=False ----- Understand.
Worksheets("DATA").Range("C5:C" & Worksheets("DATA").Range("C" & Rows.Count).End(xlUp).Row).Name = "CATEGORY" ----- Understand.
Worksheets("DATA").Columns("C:J").EntireColumn.AutoFit ----- Understand.
Worksheets("DATA").Protect Password:="-" ----- Understand.
Range("B1").Select ----- Understand.
End Sub
Thank you for your help and time.