Thursday, April 28, 2016

Get FileName list form a Folder in EXCEL

The code below retrieves the file in this directory and creates a list of their names and paths:

Sub GetFileNameList()

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer

'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get the folder object
Set objFolder = objFSO.GetFolder("C:\TMP")

i = 1
'loops through each file in the directory and prints their names and path

For Each objFile In objFolder.Files

    'print file name
    Cells(i + 1, 1) = objFile.Name

    'print file path
    Cells(i + 1, 2) = objFile.path
    i = i + 1

Next objFile

End Sub

Friday, April 8, 2016

Get alternating row colors, using conditional formatting in Excel

I got a questing about how to set alternative color in excel sheet when not using table.

Steps:
1) Select the rows you want alternate color
2) go to Conditional Formatting and create New Rule
3) Select "Use a Formula to determine which cells to format" from rule type
4) Put "=(MOD(ROW(), 2)=0)" without quotes in the formula values
5) Click Format button, and apply format required and that's all..

Wednesday, April 6, 2016

How to Test a Database Connection String using NotePad

Create and Configure a Universal Data Link (.udl) File with Notepad.

I just came across a way to test a data provider’s connection string (like a SQL Server database) with the help of a plain text file using Notepad.  To investigate and test out if your connection string works, you’re going to want to create a UDL file. 

To do this, follow these steps:
1.Open up Notepad and create an empty text file, then click File -> click Save -> and save it with the File name: TestConnection.udl to your desktop.
2.Go to your desktop and double-click on the TestConnection.udl file you just created and the Data Link Properties box will popup.
3.Select the Provider tab and Find the provider that you want to connect with and click Next >>
4.Now from the Connection tab, select or enter your source/ server name  then enter information to log on to server -> and select the database on the server. 
5.Click Test Connection and click OK to save the file.

Note: If errors occur during testing of your connection string, you will get a popup box with the error message.

Once, you've successfully tested your connection string, now go and compare the details of your TestConnection.udl with your (website) project connection string to see if they are similar.