Sunday, 21 July 2013

Copy Text File In WorkSheet And Some Important Query On Vba Programming.

Here i write a some queries and code which  is generaly use in vba program:-

Copy Text File In Worksheet :-
We create  a  module for this process and give the address of file where  it is locate.
Just see the below code and try it.

Sub GetDataFromTextFiles()
 Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim objFolder
    Set objFolder = fso.GetFolder("C:\ForSample")       
    Dim i As Integer: i = 1
    Dim FileName As Variant
    Dim LineText As String
    Dim str As String
    Dim objFile
    For Each objFile In objFolder.files
        str = ""
         FileName = objFile
         Open FileName For Input As #50
         While Not EOF(50)
            Line Input #50, LineText
            str = str & LineText
         Wend
        ActiveSheet.Cells(i, 1).Value = str
        i = i + 1
        Close #50
    Next
End Sub



Copy the data   from to sheet to anther in workbook :-
1) Sheets(SheetName1).Range(A1,D2).Value = Sheets(SheetName2).Range(A1,D2).Value
2) Sheets(SheetName1).Cells(row,col).Value = Sheets(SheetName2).Cells(row,col).Value

How to call a Excel functions in Vba:-
Here 'd'  ,'c' and 'e' as integer and we write this code inside the Vba module-

 d = Application.WorksheetFunction.Power(d1, 0.5)
 e = Application.WorksheetFunction.Power((c * d), 0.25)
Note- The power function is not accept the negative(-ve) values.




No comments:

Post a Comment