What is the syntax to open a userform?

<userform name>.Show
'example
frmHome.Show

 

Advertisements

What is the syntax to call a local procedure?

Call <procedure name>
'example
Call loadSheet

Sub loadSheet()
    'code here
End Sub

 

What is the syntax to retrieve all open workbooks in Excel?

'wb.Name holds the name of the open workbook
Dim wb As Workbook
For Each wb In Application.Workbooks
 <code here with involving wb.Name>
Next wb
'example
Dim wb As Workbook
For Each wb In Application.Workbooks 'for each open workbook, pass the name to lookupEGA()
   MsgBox wb.Name
   lstWorkbooks.AddItem wb.Name
Next wb

 

What is the syntax to open a userform in the top-right screen corner?

 Me.StartUpPosition = 0
 Me.Top = Application.Top + 25
 Me.Left = Application.Left + Application.Width - Me.Width - 25
'example - place in UserForm_Activate procedure
Private Sub UserForm_Activate() 'when form opens
   Me.StartUpPosition = 0
   Me.Top = Application.Top + 25
   Me.Left = Application.Left + Application.Width - Me.Width - 25
End Sub

 

What is the syntax to open a folder through a hyperlink?

Dim sXLFile As String
sFolder = “<folder’s filepath>
ActiveWorkbook.FollowHyperlink Address :=sFolder, NewWindow:=true

To learn how to find a folder’s filepath, click here.

‘example that opens the Downloads window upon clicking link
Dim sXLFile As String
sFolder = “C:\Users\jwatson\Downloads”
ActiveWorkbook.FollowHyperlink Address :=sFolder, NewWindow:=true