Disabling workbookopen Event for XLSB file - xlsb

I have the following issue:
I created an Excel sheet in XLSB format.
To protect that sheet, password generated by performing some operations on present month and year which would be a numeric value.
Used input box to get a password from the user in a string variable.
step 2 and 3 done in workbookopen event.
I closed the workbook and when again opened was prompted for the password which would never match even though I know the password.
What to do now? I have tried disabling macros but it doesn't seem to work.
finally tried following command
Application.EnableEvents = False
Which does exactly what i want but is not working for my sheet, though same is working fine for another trial sheet.
Sub disableCtrEvents()
Application.EnableEvents = False 'disable Events
Workbooks.Open "<path>\Wall area.xlsb"
Workbooks.Open "<path>\STAAD to steel drawing.xlsb"
End Sub
Following three files can be dowloaded from the link
test.xlsm - containing events disabling code (written above) and code to open other two sheets.
wall area.xlsb - trial sheet to check whether events are disabled or not.
STAAD to steel drawing.xlsb - actual file wherein i want to disable workbook open event
link - https://drive.google.com/open?id=1d_3Tu_-qIYErgYVkOjrCP4b8sZagXxF1

Related

Blocking code in custom message box in VB6

In my vb6 project, I created my own msgbox using a form, due to difficulties in changing
the font/language of in-built msgbox. A search with google gave the idea of own msg-
box rather than trying msgbox of VB. Now the problem is : - when the user exits the
program, 3 options are given: to close, to restart and to cancel exit. The user need not
again go through the process of giving password etc in restart option. If I give cancel =
true in the QueryUnload event, then 2nd option does not work, 3rd option works. If
cancel = true is not given, 2nd option works, but 3rd option does not. It appears that
the main form does not get unloaded if cancel = true. Unless & until the main form
unloads, the program will not work with the fresh data to be given by the user in the
initial Form. Since the code after "msgbox.show" depends on options, it is not possible
to write that code in the same sub, not even in the same form code. Is there any way
to stop the subsequent code after "msgbox.show" and continue the same after getting
option? (like in the in-built msgbox of VB.) I am not an expert in VB, so please correct
if I made some mistake; also help with advice/suggestions.
EDIT:- [Extended explanation]
The 3 forms in my project:
Initial form for password, data etc. This is input Form for user.
Main Form. This Form shows the results after process of input.
frmMsgBox. This is a custom msgbox created using a form.
Main Form code portion. Code for closing the program:
Private Sub Form_QueryUnload(Cancel as.......)
cancel = True
frmMsgBox.Label1.caption = Do you wish to 1.Exit 2.Restart
3.Cancel the exit?
frmMsgBox.Show
End sub
(The above msgbox is almost like an in-built msgbox in VB with
vbYesNoCancel buttons) The message is in regional language,
which was the main reason forced me to use my own msgbox.
After MsgBox appears, the user selects one of the above options
using 3 commandButtons placed in that Form. The code after
clicking these buttons is written in the code portion of frmMsgBox:
Command1_Click 'This is for Exit from the Program.
All Forms.unload, All forms set to nothing, end.
Command2_click 'This is for restarting the Program.
Unload Main Form, set to nothing
Load Initial Form
Initial Fom.show
frmMsgBox.Hide
Command3_Click 'This is for cancelling the exit request.
Main Form.Show
frmMsgBox.Hide
With the above code, I have no problem with options 1 & 3,
i.e; to exit from the program or to start. The frmMsgBox hides,
the initial form shows - these are OK, but the main form does
not unload nor it is removed from memory. Because of this,
whatever new data is given by the user in the initial form now
is not being processed, the main form is struck with the old results.
If cancel = true is removed from the code above, Options 1 & 2
are OK, but option 3 does not work. Then the Main Form loses
all its results (all labels, texts etc in that Form turn blank.)

gSheet - Google Apps Script - copy DataValidation - Dropdown: "Loading ..."

Via Google Apps Script I am copying Data Validation rules from a range with one col to several cols offsetted to said one. Its been done on a freshly duplicated sheet - also by script (with: .insertSheet(newSheetName, {template: sheet});)
Code to copy data validations from one col to the next on the right:
Seems to execute somehow. However, when I want to use the dropdown on that cells to select a data point I just shows a field "Loading ..."
When checking the data validation via the gui the right named range is set as the "list of a range".
Even when then resetting it manually it still shows that "Loading ..." field.
Whats wrong there?

Comparing Data In Text Boxes in Visual Studio 2013

So I mostly use Microsoft Excel for a lot of my work and the most "Programming" I do is writing basic logical functions in excel.
I am setting up a windows form in Visual Studio 2013 and I want to the end user to be able to be able to confirm that the data they input into TEXTBOX1 matches what is in TEXTBOX2.
So normally in excel I can just write =IF(C2=D2,"Yes","No")
So basically I want to be able to input data in the carton field and then in the label field and if it matches I want it to say yes in the text box at the bottom.
I tried writing
If CartonBarcode = LabelBarcode Then
PartCheck = "Yes"
Else : PartCheck = "No"
End If
but that hasn't worked - I am very new to VB so please be gentle.
Eventually I also want to be able to append the scanned data (If the two text boxes match) into an excel spreadsheet.
Thanks in advance for all your help =)
Thanks for your help Mark - that makes a lot of sense.
I added this IF Statement to the PartCheck text box but it doesn't seem to display Yes or No regardless of what I put in.
It now throws two errors (look to be the same error on each line.)
Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'
Any further help you can provide would be fantastic
Screenshot of errors
I then changed PartCheck = "Yes" to PartCheck.Text = "Yes" and it runs but then nothing displays in the PartCheck Text Box
In WinForms, TextBox and other GUI components (e.g. Label, Button) are objects, with properties and methods to interact with them. If you want to compare the text that has been entered into two TextBox objects, you will need to compare their Text properties. e.g.
Update
Updated code below based on your updated question. You are correct that you need PartCheck.Text = "Yes" to set it correctly. Your current issue is when you are performing the check. You are handling the TextChanged event for your PartCheck TextBox, but your logic should really be triggered when either the CartonBarcode or LabelBarcode text is changed. You can either have TextChanged handlers for both of those TextBox controls, and call a common subroutine to perform the check, or have a common TextChanged handler, as shown below:
Private Sub Barcode_TextChanged(sender As Object, e As EventArgs) _
Handles CartonBarcode.TextChanged, LabelBarcode.TextChanged
If CartonBarcode.Text = LabelBarcode.Text Then
PartCheck.Text = "Yes"
Else
PartCheck.Text = "No"
End If
End Sub

HTA, Removing Selected Items from a Combo Box

So i have an HTA that populates a combo box based on SCCM client installs that are available and have not yet been run. Everything works fine except for the combo box whats supposed to happen is whatever program is selected runs, and is then installed and removed from the Combo box. However no matter what program i select the first Item is removed every time, I've tried a few different variations but nothing seems to work, any help is appreciated.
Dim i
strSelectedValues = ""
' Check all the Options of the ListBox
For i = 0 To (objComboBox.Options.Length - 1)
' Check if the Current Option is Selected
If (objComboBox.Options(i).Selected) Then
' Collect only the Selected Values
strSelectedValues = strSelectedValues & objComboBox.Options(i).Value
End If
Next
'Remove selected program to install from the Combo box list
ComboBox1.Remove(SelectedItem)
According to this authority, .remove needs the number/index of the option to remove. SelectedItem seems to be undefined/empty/for practical purposes: zero in your code; then it seems reasonable that the first option vanishes. So try
ComboBox1.Remove ComboBox1.selectedIndex
(perhaps guarded by a check that there is a selected option - or should it go into the loop?)

OnOpenExcelWorksheet Event To Trigger When Worksheet Opens?

How can I run code when a Worksheet opens? (The code that I want to run is contained in the opening worksheet)
You can put certain code in the Worksheet_Activate() function which will run when the sheet is selected. Additionally, use the Worksheet_Deactivate() to run code when you leave the wokrsheet and go to another one. These functions go in the worksheet object code.
Private Sub Worksheet_Activate()
MsgBox ("Hi")
End Sub
Private Sub Worksheet_Deactivate()
MsgBox ("Bye")
End Sub
I'm not sure how to get code to run when a worksheet opens, but you can get it to run when a workbook opens.
In the VBA editor, open the Microsoft Excel Object called "ThisWorkbook." At the top of the editor window, you should see two drop-down boxes: (General) and (Declarations). Change the (General) combo box to be "Workbook."
This will give you method called Workbook_Open(). Code placed in this method will execute when you open the Excel Workbook.
Furthermore, you have more events at your disposable, available in the (Declarations) section when you have Workbook selected, such as SheetActivate and SheetChanged, among others. I haven't used those methods, but they may be something to try if you need events related to individual worksheets and not just the entire workbook.
One way I have found to autorun while opening with Worksheet code only -without Workbook code - is with the Calculate event triggered by i.e. a formula =Now().
This can be relevant if copying the sheet to a new workbook should be allowed and the VBA code to run there as well.
You can also use static variables to run code only once in the Worksheet.Activate function like this...
Private Sub Worksheet_Activate()
Static Loaded as Variant
If Loaded <> True then
MsgBox ("Hi")
Loaded = True
End If
End Sub

Resources