Friday, January 11, 2013

Identify Browser Version using Excel VBA:-

Identify Browser Version using Excel VBA:-




Sub CheckWebOptions()

Dim wkbOne As Workbook
Set wkbOne = Application.Workbooks(1)

‘ Determine if IE8 is the target browser.


If wkbOne.WebOptions.TargetBrowser = msoTargetBrowserIE6 Then

MsgBox "The target browser is IE6 or later."

ElseIf wkbOne.WebOptions.TargetBrowser = msoTargetBrowserIE5 Then

MsgBox "The target browser is IE5 or later."

ElseIf wkbOne.WebOptions.TargetBrowser = msoTargetBrowserIE4 Then

MsgBox "The target browser is IE4 or later."

ElseIf wkbOne.WebOptions.TargetBrowser = msoTargetBrowserV4 Then

MsgBox "Microsoft Internet Explorer 4.0, Netscape Navigator 4.0, or later."

ElseIf wkbOne.WebOptions.TargetBrowser = msoTargetBrowserV3 Then

MsgBox "Microsoft Internet Explorer 3.0, Netscape Navigator 3.0, or later."

Else

MsgBox "The target browser is not in the given list"

End If


End Sub





Wednesday, December 12, 2012

Cell Border in Excel

Apply Cell Border in Excel:-

Function BorderLine()


'Put Border line in selected cells.

Selection.Borders(xlEdgeTop).LineStyle = xlContinuous

Selection.Borders(xlEdgeTop).Weight = xlThin

Selection.Borders(xlEdgeTop).ColorIndex = xlAutomatic

Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous

Selection.Borders(xlEdgeBottom).Weight = xlThin

Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic

Selection.Borders(xlEdgeRight).LineStyle = xlContinuous

Selection.Borders(xlEdgeRight).Weight = xlThin

Selection.Borders(xlEdgeRight).ColorIndex = xlAutomatic

Selection.Borders(xlInsideVertical).LineStyle = xlContinuous

Selection.Borders(xlInsideVertical).Weight = xlThin

Selection.Borders(xlInsideVertical).ColorIndex = xlAutomatic

Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous

Selection.Borders(xlInsideHorizontal).Weight = xlThin

Selection.Borders(xlInsideHorizontal).ColorIndex = xlAutomatic

End Function

Exiting a Loop

In the loop above if you want the loop to stop when it finds the value 99 you can add this line of code within the loop:


If Selection.Value = 99 Then Exit Do

Exit allows you to get out of almost anything like:

Exit Sub
Exit For

Exit Do

Delete the value in the cell

Sub proDelete()

Range("B1").Select

Do Until Selection.Value = "xxx"
If Selection.Value = "" Then
Selection.EntireRow.Delete
Else
Selection.Offset(1, 0).Select
End If
Loop
Range("A1").Select
  End Sub

Stop users from scrolling about in Excel

Stop users from scrolling about in Excel:-

Here's a very simple line of code that will stop users from scrolling about a chosen worksheet. To place the code in, right click on the sheet name tab, select "View Code" and paste in this code.


Private Sub Worksheet_Activate()
    Me.ScrollArea = "A1:T50"
    'To set back to normal use:
    Me.ScrollArea = ""
End Sub

Find the content in Excel with Loop

Sub WithLoop()

Dim rCell As Range

For Each rCell In Cells

If rCell.Value = "Find Me" Then
rCell.Activate
Exit For
End If

Next rCell
  End Sub

Find the content in Excel without Loop

Sub NoLoop()


Cells.Find(What:="Find Me", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

End Sub