a few very quick questions /plz help^^\

venomatic

New Member
Joined
Jun 20, 2011
Messages
36
Howdy folks, hope I can throw in a few q's that I'm trying to grasp. Every little bit :help:s! Thanks in advance! Starting with the least code:


1) For module-level variables, is Dim the same thing as Private?

2) If we want to assign a variable to a method or property, would that variable always be a variant?

3) For event-handler procedures, is it fair to say you can't have more than one of the same type [e.g., Workbook_Open() ]?



4) Sorry for a silly question, but is & the same thing as + (aside from addition)?

5) Consider the following, a simple procedure that modifies even-# columns with a new width:
Sub widthAdjust()
Dim Col
For Each Col In Worksheets("Sheet7").Columns
If Col.Column Mod 2 = 0 Then Col.ColumnWidth = 8.43
Next Col
End Sub
I was wondering what data type is Col? The procedures runs fine as a Variant, but I don't know if its a Long or a ("column") object. It would make sense if it was an object, since that would explain the idea of "Col.Column", i.e. instance of an object.

6) For any Sub procedure, let's say:
Code:
[COLOR=darkorange]Sub myprocedure()[/COLOR]
[I][COLOR=darkorange]statements[/COLOR][/I]
[COLOR=darkorange]End Sub[/COLOR]
So is it fair to say that () doesn't take arguments? Is that idea similar to optional arguments?



7) Consider a simple event-handler procedure that asks you if you want back-up your work before you close Excel:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Code:
[B]Dim Msg As String[/B]
[B]Dim Ans As Integer[/B]
[B]Dim FileName As String[/B]
[B]Msg = “Would you like to make a backup of this file?”[/B]
[B]Ans = MsgBox(Msg, vbYesNo) '//vbYesNo is an argument[/B]
[B]If Ans = vbYes Then[/B]
[B]    FileName = “F:\BACKUP\” & ThisWorkbook.Name[/B]
[B]    ThisWorkbook.SaveCopyAs FileName[/B]
[B]End If[/B]
[B]End Sub[/B]
I was curious, what does Cancel do here exactly? And can I replace vbYesNo with, let's say, the inputbox function?

Cheers!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
1. Yes.

2. You can assign a Variant to anything. In general, it's better to assign a variable of the same type (or Variant subtype) as the property. You can't assign a variable to a method; you can assign a variable to the object returned by a method.

3. More than fair, it's a fact; you can't have two procedures with the same name in a module.

4. For string variables, yes, but the & always catenates, while the + will add numeric variables. Stick with &.

5. Range

6. myprocedure does not accept any arguments. Optional arguments must appear in the signature with the Optional keyword.

7. From Help: If the event procedure sets this argument to True, the close operation stops and the workbook is left open.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top